Advertisement
brandblox

ImgLab-2-(25-9-24)

Sep 25th, 2024 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. Filter.py
  2. import matplotlib.pyplot as plt
  3. from skimage import data, filters
  4.  
  5.  
  6. image = data.coins()
  7.  
  8. edges = filters.sobel(image)
  9. plt.imshow(edges, cmap='gray')
  10. plt.show()
  11.  
  12.  
  13.  
  14. FilterCanny.py
  15. import numpy as np
  16. import cv2
  17. img = cv2.imread('peter.jpg')
  18. t_lower = 50
  19. t_upper = 100
  20. apenture_size= 5
  21. edge = cv2.Canny(img,t_lower,t_upper,apenture_size)
  22.  
  23. cv2.imshow('Original image',img)
  24. cv2.imshow('Edge image',edge)
  25. cv2.waitKey(0)
  26. cv2.destroyAllWindows()
  27.  
  28. Prewitt / Robert is Homework
  29. import numpy as np
  30. import cv2
  31. from skimage.filters import prewitt, roberts
  32. from skimage import io, color
  33.  
  34. # Load the image
  35. img = cv2.imread('peter.png')
  36.  
  37. # Convert the image to grayscale (Prewitt and Roberts work on grayscale)
  38. gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  39.  
  40. # Perform Prewitt edge detection
  41. prewitt_edges = prewitt(gray_img)
  42.  
  43. # Perform Roberts edge detection
  44. roberts_edges = roberts(gray_img)
  45.  
  46. # Display the results
  47. cv2.imshow('Original Image', gray_img)
  48. cv2.imshow('Prewitt Edge Detection', prewitt_edges)
  49. cv2.imshow('Roberts Edge Detection', roberts_edges)
  50.  
  51. cv2.waitKey(0)
  52. cv2.destroyAllWindows()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement