The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images, see [1]. The following table shows an example input image, a set of input parameters for the canny edge detector algorithm (explained below), and the corresponding edge image.
Noise reduction
Since edge detection is easily affected by noise, a Gaussian filter is applied to the image first.
Find the intensity and angle of each pixel in the image
The smoothed image from stage 1 is then filtered with edge detection filters in both horizontal and vertical direction, resulting in \(G_x\) and \(G_y\). The intensity and angle of each pixel is calculated as follows:
The gradient direction is always perpendicular to edges. It is rounded to one of four angles representing vertical, horizontal and two diagonal directions.
Thin the edge by non-maximum suppression
For each pixel in the image, check if the intensity is a local maximum in the gradient direction. If it is, keep it as edge pixel, otherwise remove it as non-edge pixel.
Double thresholding
Two thresholding values are provided and they are called strong threshold and weak threshold. For each pixel, if the intensity is greater than the strong threshold, then it is marked as strong edge. If the intensity is less than the weak threshold, then it is marked as non-edge. Any intensity value in between of the strong threshold and weak threshold is marked as weak edge.
Track edge by hysteresis
If the weak edge is connected to a strong edge, then this weak edge is changed into a strong edge. Repeat this process until all the weak edges that are connected to strong edges are found. Mark the rest of weak edges as non-edge.
C API functions
For list of limitations, constraints and backends that implements the algorithm, consult reference documentation of the following functions: