Message Boards Message Boards

1
|
7875 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Why this simple case of watershed segmentation fails?

The question has been posted on StackExchange. https://mathematica.stackexchange.com/questions/160304/why-this-simple-case-of-watershed-segmentation-fails.

I tried a simple experiment today with WatershedComponents. I took this image from: https://fr.mathworks.com/help/images/ref/watershed.html (readers should use the image from the link above and crop the image themselves, rather than using the image directly below)

enter image description here

then I binarized the image

bin = Binarize[img];

the distance transform of the image yields dist:

dist = DistanceTransform[bin]//ImageAdjust;

enter image description here

Now to determine the seeds:

seeds = MaxDetect[dist]; (* notice two nice seeds in the image *)

enter image description here

finally using WatershedComponents i get this:

WatershedComponents[bin, seeds] // Colorize

enter image description here

Note: This is clearly how they should not be segmented. In contrast please see the segmentation performed by Matlab (link mentioned above). I tried using different methods but could not get a proper segmentation. What am i doing wrong?

POSTED BY: Ali Hashmi
2 Replies

Try with applying the watershed segmentation directly to the ridge lines:

ridgelines = RidgeFilter[bin, 3] // ImageAdjust
wsc = WatershedComponents[ridgelines, seeds];
wsc // Colorize
HighlightImage[img, wsc // Image // Binarize // ColorNegate]

enter image description here

POSTED BY: massimo fazio

This follows an example in the documentation:

binImg = Binarize[img];

distImg = DistanceTransform[binImg] // ImageAdjust;

negDistImg = ColorNegate[distImg] // ImageAdjust;

ImageMultiply[binImg, Image[WatershedComponents[negDistImg], "Bit"]]

This works, with 'img' as the image.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract