Canny edge detector
lastmod 2023-11-05created 2017-06-2816 edits
The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. It was developed by John F. Canny in 1986. Canny also produced a computational theory of edge detection explaining why the technique works.
It is a type of Edge detect algorithm.
Step
Since understanding the paper "A Computational Approach to Edge Detection" is not easy, to summarize it very simply as below, Canny edge consists of 4 steps.
- Blur the image with Gaussian Blur to remove noise.
- Find edges using the Sobel Edge Detector.
- Non-maxima Suppression: Use as an edge only where the Edge magnitude is a maximum. Here, instead of checking whether it is the maximum over all 3x3 neighbors, the search direction is determined by considering the edge orientaton.
- Connect the Edges (Hysteresis analysis)
Non-maxima Suppression
Use as an edge only where the edge magnitude is a maximum. Here, instead of checking whether it is the maximum over all 3x3 neighbors, the search direction is determined by considering the edge orientaton.
One of the characteristics of Canny Edge is that it uses two thresholds: in this process, if the edge magnitude is greater than the high threshold, the pixel is marked as an edge pixel, and if the magnitude is greater than the low threshold, it is marked as an edge when it is adjacent to an edge pixel later, when the edges are connected (hysteresis analysis).
Example
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('messi5.jpg',0)
edges = cv2.Canny(img,100,200)
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()
See also
- OpenCV
- Edge detection
- Hough Line Transform
- Image Processing
- Image Contours (image contour extraction)
- Sobel operator
Favorite site
- Wikipedia (en) Canny edge detector
- OpenCV: Canny Edge Detection
- Edges detection #3- Canny edges
- Canny Edge Detector
- A fledgling programmer at thirty :: Corner Detection - #2 Canny Edge 1
- Canny Edge implementation
- Canny edge detection (Canny Edge Detection)
- OpenCV #7-1 Example (detecting image outlines with the Canny operator)
- (C++ opencv) Detecting boundaries in an image, Edge detection
- [Recommended] Image edge detection (Sobel, Canny Edge): principles and usage - gaussian37 2