File Exchange

image thumbnail

Canny Edge Detector

version (3.09 KB) by Amarjot
The code computes the edge map for a grayscale image using canny detector


Updated 11 Mar 2013

View License

The code is divided as:

1. Smooth the input image with a Gaussian filter.
2. Compute the gradient magnitude and angle images.
3. Apply nonmaxima suppression to the gradient magnitude
4. Use double thresholding and connectivity analysis to detect
the link edges.

Running the code:

[Ioutput]= cannydetector(I);

Cite As

Amarjot (2020). Canny Edge Detector (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Heejune Ahn

Hi, Thx for sharing your work. It is pretty well implemented.
But, there is a couple of errors and some minor things to improve.
1) You misunderstood the edge direction and gradient direction and using gradient direction than edge direction.
Because edge direction is perpendicular to gradient direction, the result is very weird finally.
2) when you calculated the angles using atan, you apply +90 degree for making the negative ones to positive one.
this is another mistakes, you should add 180 degree for this purpose.

Some minior comments
1. gradingedges functions in fact simply removes the edge less than Tl. So you donot need to if > Th elseif Tl and Th
2. your filter is not a Gaussian filter, so make the results is different from the original result of Matlab edge('Canny')
3. too many for loop, you could use vectorization.

Thanks. I could send you a upgraded one if you want it.

is it compatible with matlab R2017a

how to read the image in this function?

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux