Name

Watershed — applies a watershed transform to an image

Calling Sequence

SegmentedImage = Watershed(Image, Marker);

Parameters

Image

2D matrix of type uint8

Marker

2D matrix of type boolean, blobs consisting of %t pixels are seeds of watershed transform

SegmentedImage

2D matrix of type int32, has the same dimensions as image

Description

This function applies a watershed transform to an image.

Examples

RGB = ReadImage('contrib\IPD-3.3\demos\teaset.png');

Image = RGB2Gray(RGB);

Gradient = EdgeFilter(Image, EDGE_SOBEL);

EdgeImage = ~SegmentByThreshold(Gradient, 60);

DistanceImage = DistanceTransform(EdgeImage);

ThresholdImage = SegmentByThreshold(DistanceImage, 8);
          
MarkerImage = SearchBlobs(ThresholdImage);

SegmentedImage = Watershed(Gradient, MarkerImage);

figure();

ColorMapLength = length(unique(SegmentedImage));

ShowImage(SegmentedImage, ...
          'Result of Watershed Transform', ...
          jetcolormap(ColorMapLength));  

See Also

DistanceTransform, EdgeFilter