The Canny module implements the Canny Edge Detector first specified by John Canny is his paper "A Computational Approach to Edge Detection". The Canny edge detector is regarded as one of the best edge detectors currently in use. The basic algorithm can be outlined as follows:

1. Blur the image slightly. This removes the effects of random black or white pixels (i.e. noise pixels) that can adversely affect the following stages. Blurring is typically accomplished using a Gaussian Blur. However, you should be able to use a box averaging filter like the Mean filter to accomplish the same effect. The mean filter can be executed faster than a Gaussian blur so for real-time applications the computational advantage can be worthwhile.

2. Compute the x and y derivatives of the image. This is basically an edge detection step. Similar to the Sobel edge detector the x and y derivatives are simply calculated by subtracting the values of the two surrounding neighboring pixels depending on which axis is being computed (left and right for x derivative and top and bottom for y derivative).

3. From the x and y derivatives you can compute the edge magnitude which basically signifies the strength of the edge detected at the current point.

4. If you were to look at the edge image at this point it would look very similar to the Sobel edge filter. Namely, the edges would be thick in many areas of the resulting edge image. To 'thin' these edges a nonmaximal filter needs to be applied that only preserves edges that are the top or ridge of a detected edge. The nonmaximal filter is applied by first analyzing what the slope of the edge is (you can determine this by the sign and magnitude of the x and y derivatives calculated in the previous steps) and use that slope to determine what direction the current edge is heading. You can then determine the two edge magnitudes perpendicular to the current heading to determine if the current pixel is on an edge ridge or not. If the current pixel is on a ridge its magnitude will be greater than either of the two magnitudes of the perpendicular pixels (think of walking on a mountain ridge with the ground decreasing on both sides of your heading). Using this ridge detection and subsequant elimination will result in very thin lined edges.

5. Once the edges have been thinned the last step is to threshold the detected edges. Edge magnitudes above the upper threshold are preserved. Edges below the upper threshold but above the lower threshold are preserved ONLY if they connect (i.e. 8 neighborhood touching) to edges that are above the upper threshold. This process is know as hysteresis and allows edges to grow larger than they would by using a single threshold without introducing more noise into the resulting edge image.



1. Theta - Select the Gaussian blur standard deviation amount. Also known as sigma. Typical values range from 0.60 to 2.40. The higher the value the greater the blurring of the image. Note that the window size of the filter is determined automatically.

2. Low Threshold - Select the low threshold above which possible edges can exist. Edges below the low threshold are removed from the image.

3. High Threshold - Select the high threshold above which edges are preserved in the image. Edges between the high and low threshold are ONLY preserved if they are connected to an edge that is above the high threshold. See hysteresis above.

4. Grayscale - To increase speed, you can select the grayscale option which will only examine the green channel to produce the line results.


SourceCanny Edge Detection

See Also

Difference of Gaussian

For more information

HIPR - Canny Edge Detector
Bill Green - Canny Edge Detection Tutorial
Noah Kuntz - Canny Tutorial

 New Post 

Canny Related Forum PostsLast postPostsViews
Detecting deformed rings
Hi, I have the following problem and I'd appreciate your help: I need to detect, ID and track a se...
8 years 5 2421