Canny() function with both Aperture size and L2gradient

Here we will use both attributes within the function.

Python3




import cv2 
  
img = cv2.imread("test.jpeg") # Read image
  
# Defining all the parameters
t_lower = 100 # Lower Threshold
t_upper = 200 # Upper threshold
aperture_size = 5 # Aperture size
L2Gradient = True # Boolean
  
# Applying the Canny Edge filter 
# with Aperture Size and L2Gradient
edge = cv2.Canny(img, t_lower, t_upper,
                 apertureSize = aperture_size, 
                 L2gradient = L2Gradient ) 
  
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.

Similar Reads

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....

Canny() function with Aperture_size

...

Canny() function with L2Gradient

This is an optional parameter that is used to specify the order of the Sobel filter used to calculate the gradient in the Canny algorithm. The default value is 3 and its value should be odd between 3 and 7. You can increase the Aperture size when you want to detect more detailed features....

Canny() function with both Aperture size and L2gradient

...