What is a Canny Edge Detection Algorithm?
Last Updated on September 18, 2020 by Editorial Team
Author(s): Charanraj Shetty
Computer Vision
A Canny edge detector is a multi-step algorithm to detect the edges for any input image. It involves the below-mentioned steps to be followed while detecting edges of anΒ image.
1. Removal of noise in input image using a GaussianΒ filter.
2. Computing the derivative of Gaussian filter to calculate the gradient of image pixels to obtain magnitude along x and y dimension.
3. Considering a group of neighbors for any curve in a direction perpendicular to the given edge, suppress the non-max edge contributor pixelΒ points.
4. Lastly, use the Hysteresis Thresholding method to preserve the pixels higher than the gradient magnitude and neglect the ones lower than the low threshold value.
Before deep-diving into the steps below are the three conclusions that J.K Canny who derived the algorithmΒ :
– Good Detection: The optimal detector must eliminate the possibility of getting false positives and false negatives.
– Good Localisation: The detected edges must be as close to trueΒ edges.
– Single Response Constraint: The detector must return one point only for each edgeΒ point.
Steps to followed during Canny Algorithm:
Noise Removal or Image Smoothing:
During the noise present, the pixel may not be close to being similar to its neighboring pixels. This might result in obtaining improper or inappropriate detection of edges. To avoid the same, we use the Gausian filter, which is convolved with the image and removes the noise, preventing the desired edges in outputΒ images.
In the below example, we are convolving gausian filter or kernel g(x,y) with an image I. Here we wish to make sure that any given pixel must be similar to its neighboring pixels in output and so we use the matrix [1 1 1] to maintain the similarity between pixels and remove theΒ noise.
g(x,y)= Gausian Distribution
I = inputΒ image
DerivativeΒ :
Calculate the derivative of filter w.r.t X and Y dimensions and convolve it with I to give the gradient magnitude along the dimensions. Also, the direction of the image can be calculated using the tangent of the angle between the two dimensions.
The above convolution results in a gradient vector that has magnitude and direction.
Below is an example of Gausian Derivatives, which finally contribute to edges in outputΒ images.
Non-Max Suppression
Along an edge, it is generally observed that few points make the visibility of the edge clearer. So we can neglect those edge points which donβt contribute more towards feature visibility. To achieve the same, we use the Non Maximum Suppression method. Here we mark the points on the curve of the edge where the magnitude is largest. This can be obtained by looking for a maximum along with a slice normal to theΒ curve.
Consider the edge in the below figure, which has three edge points. Assume point (x,y) as the point having the largest gradient of edge. Check for the edge points in the direction perpendicular to the edge and verify if their gradient is less than (x,y). If the values are less than (x,y) gradient, then we can suppress those non-maxima points along theΒ curve.
Hysteresis ThresholdingΒ :
If the gradient at a pixel isΒ :
– Above βHighβ declare it as an βedgeΒ pixel.β
– Below, βLowβ declares it as a βnon-edge pixel.β
– Between βlowβ andΒ βhigh.β
- Consider its neighbors iteratively then declare it an βedge pixelβ if itβs connected to an βedge pixelβ or via pixels between βlowβ andΒ βhigh.β
Thanks for readingΒ !!
Source Reference of Dr. Mubarak Shah youtubeΒ videos.
What is a Canny Edge Detection Algorithm? was originally published in Towards AIβββMultidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.
Published via Towards AI