Canny Edge Detection

Simpson family

The Canny Edge Detection is a popular edge detection algorithm. It was developed by John F. Canny in 1986. It is a multi-stage algorithm. Also known to many as the optimal detector, Canny algorithm aims to satisfy three main criteria:

  • Low error rate: Meaning a good detection of only existent edges.
  • Good localization: The distance between edge pixels detected and real edge pixels have to be minimized.
  • Minimal response: Only one detector response per edge.

Canny Edge Detection in OpenCV: cv2.Canny().

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread(r'C:\Users\tiba\Documents\python\Images\simpsons.JPG',0)
edges = cv2.Canny(img,100,200)
files = r'C:\Users\tiba\Documents\python\Images\edges.JPG'
cv2.imwrite(files,edges)
plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])
plt.show()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.