I am trying to write code for canny edge detection but it is not giving exact output like inbuilt function.can any one help me

5 vues (au cours des 30 derniers jours)
i attached code,pls check it and tell me where i did wrong in that

Réponse acceptée

David Young
David Young le 17 Nov 2014
Modifié(e) : David Young le 17 Nov 2014
The differences are quite small, and I don't think there is very much wrong. My own implementation of the Canny edge detector also produces slightly different results from edge().
Possible causes of differences include:
  • You use a rounded approximation to the Gaussian kernel for smoothing. It is likely that edge() uses a different approximation.
  • You use a symmetrical operator (the Sobel operator) for differencing. I believe edge() uses non-centred nearest-neighbour differences, which introduce a half-pixel shift in the gradient estimate positions. Personally I prefer your approach.
  • Your choice of non-maximum suppression is to quantise the gradient direction to the nearest 45 degrees and to compare gradient magnitudes at the pixels in the relevant direction. There are a number of other possible approaches - for example you can interpolate the gradient magnitude and then compare along the gradient direction. Canny did not specify what to do here, and everyone makes their own choice. I am not sure what edge() does, but it may well do something different from your method.
  • Your implementation of hysteresis thresholding is not correct. It is not sufficient to test whether any of the nearest neighbours exceeds the high threshold. You need to test whether the current pixel can be connected to a pixel where the gradient exceeds the high threshold.
I suspect the second point above is the most important effect in making a difference between your output and that of edge(). The last point above is the only one which I would identify as a definite error on your part.
Your code is not in a good MATLAB style, by the way - all your loops could be vectorised - but that's another story.
  3 commentaires
Mahesh Kumar
Mahesh Kumar le 19 Nov 2014
Modifié(e) : Mahesh Kumar le 20 Nov 2014
if i change thresholds it is showing big difference compare to inbuilt,can you suggest me why it is showing like that
David Young
David Young le 20 Nov 2014
There are a number of ways of implementing hysteresis thresholding. To see the way I chose, you could look at this entry on the File Exchange.
Changing the thresholds will always have a big effect. Note that the thresholds used by edge() are relative to the maximum gradient. But I'm not sure what exactly you'd like me to explain.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by