Canny Edge detection is an Algorithm consisting of 4 major steps
- Reduce Noise using Gaussian Smoothing.
- Compute image gradient using Sobel filter.
- Apply Non-Max Suppression or NMS to just jeep the local maxima
- Finally, apply Hysteresis thresholding which that 2 threshold values T_upper and T_lower which is used in the Canny() function.
Input Image:
Basic example of Canny() function
Python3
import cv2 img = cv2.imread( "test.jpeg" ) # Read image # Setting parameter values t_lower = 50 # Lower Threshold t_upper = 150 # Upper threshold # Applying the Canny Edge filter edge = cv2.Canny(img, t_lower, t_upper) cv2.imshow( 'original' , img) cv2.imshow( 'edge' , edge) cv2.waitKey( 0 ) cv2.destroyAllWindows() |
Output:
Python OpenCV – Canny() Function
In this article, we will see the Canny Edge filter in OpenCV. Canny() Function in OpenCV is used to detect the edges in an image.
Syntax: cv2.Canny(image, T_lower, T_upper, aperture_size, L2Gradient)
Where:
- Image: Input image to which Canny filter will be applied
- T_lower: Lower threshold value in Hysteresis Thresholding
- T_upper: Upper threshold value in Hysteresis Thresholding
- aperture_size: Aperture size of the Sobel filter.
- L2Gradient: Boolean parameter used for more precision in calculating Edge Gradient.