Slmaan

Task 4: Edge Detection

Apr 18th, 2023 (edited)
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import numpy as np
  2. import cv2 as cv
  3. from matplotlib import pyplot as plt
  4. def canny_edge_detection(image, threshold1, threshold2):
  5.     gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
  6.     edges = cv.Canny(gray, threshold1, threshold2)
  7.     return edges
  8. def main():
  9.     image = cv.imread("Q_3.jpg")
  10.     edges1 = canny_edge_detection(image, 100, 200)
  11.     edges2 = canny_edge_detection(image, 50, 100)
  12.     plt.subplot(131),plt.imshow(image,cmap = 'gray')
  13.     plt.title('Original Image'), plt.xticks([]), plt.yticks([])
  14.     plt.subplot(132),plt.imshow(edges1,cmap = 'gray')
  15.     plt.title('Edges with threshold 1:100, threshold 2:200'), plt.xticks([]), plt.yticks([])
  16.     plt.subplot(133),plt.imshow(edges2,cmap = 'gray')
  17.     plt.title('Edges with threshold 1:50, threshold 2:100'), plt.xticks([]), plt.yticks([])
  18.     plt.show()
  19. if __name__ == '__main__':
  20.     main()
Advertisement
Add Comment
Please, Sign In to add comment