Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to understand the differences between EdgeDetect and MorphologicalPerimeter (while researching this other question). I understand that, if the image background is not white, they will yield completely different results:

enter image description here

However, I am not sure whether they are guaranteed to return the same result if the background is white. In my tests, they do:

enter image description here

Could someone confirm this conclusion, or show a counter-example?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

No, they're not the same, and will not, in general, give the same result because they're two very different operations.

  • MorphologicalPerimeter gives a Boolean output according to the following logic:

    1. 1 — If the pixel value is 1 (i.e., white) and at least 1 pixel in its 8-pixel neighbourhood is 0.
    2. 0 in all other cases.

    Here's an example with a simple 20x20 image with 1 black pixel along the diagonal. You can actually follow the logic above to verify the output (assume 0 outside the edge for pixels along the border)

    img = ColorNegate@Image@IdentityMatrix[20];
    MorphologicalParameter[img]
    

    enter image description here

  • EdgeDetect, by default, uses the Canny edge detector which is a lot more complicated, multi-step algorithm unlike MorphologicalPerimeter. Roughly speaking, it convolves it with a Gaussian filter, followed by a non-maximum suppression step, which basically sets all pixels that aren't a local-maxima to zero. You can read more about it in the Wikipedia article.

    Performing an edge detection on the above image gives you:

    EdgeDetect[img]
    

    enter image description here

    You can visibly see the difference between the two images above, especially at the corners and the borders.

share|improve this answer
1  
thanks for this very clear answer! –  F'x Apr 15 '12 at 7:46
add comment

In the help file it says "MorphologicalPerimeter[image] is equivalent to MorphologicalPerimeter[image,0]" treats values above t as foreground.. So, using value other than 0 gives the result you need.

share|improve this answer
    
Sorry, but I don't think that answers the question. I'm asking: for a white background, are MorphologicalPerimeter (with its implied zero as second parameter) the same as EdgeDetect? –  F'x Apr 14 '12 at 22:05
    
well the point is: the function yields a binary image in which pixels considered to be on the morphological perimeter have value 1 and others have value 0. So every thing is above 0 so it's all black... –  s.s.o Apr 14 '12 at 22:11
add comment

As R.M already indicated both methods are completely different. EdgeDetect uses gradient based methods, which detect areas in which gradients change sharply. This works nicely on grayscale and color images, as gradients are easy to define there. The basic parameter here is the scale of the gradients that are taken into account.

MorphologicalPerimeter on the other hand, uses a strictly binary approach as explained by R.M. So, how can it work on grayscale and color images then? Well, simple, it uses Binarize or something equivalent internally. You can see that the parameters of Binarize and MorphologicalPerimeter behave identically:

Mathematica graphics

The basic parameter of MorphologicalPerimeter is the threshold, which is principally different from the gradient scale of EdgeDetect.

That EdgeDetect and MorphologicalPerimeter are not identical, even in your "figure 8" example where they seem similar can be easily determined using:

ImageData[MorphologicalPerimeter[Graphics[Style[Text["8"], 400]]]] == 
 ImageData[EdgeDetect[Graphics[Style[Text["8"], 400]]]]

(*
==> False
*)

In the zebra example MorphologicalPerimeter can output more than a black image if you tweak the scale parameter:

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.