WatershedComponents[image]
computes the watershed transform of image, returning the result as an array in which positive integers label the catchment basins.
WatershedComponents[image,marker]
uses a binary image marker to indicate regions where basins may be created.
WatershedComponents[video,…]
computes watershed segmentation on frames of video.
WatershedComponents
WatershedComponents[image]
computes the watershed transform of image, returning the result as an array in which positive integers label the catchment basins.
WatershedComponents[image,marker]
uses a binary image marker to indicate regions where basins may be created.
WatershedComponents[video,…]
computes watershed segmentation on frames of video.
Details and Options
- WatershedComponents, also known as watershed transform, is an image segmentation algorithm that segments areas of lower intensity (basins) enclosed in between brighter ridges.
- WatershedComponents[image] finds basins at each regional minimum in image.
- WatershedComponents works with 2D and 3D images as well as video inputs.
- WatershedComponents works with binary, grayscale, and multichannel images, operating on the intensity averaged over all channels.
- In the returned label array, zeros represent positions that do not belong to any foreground component.
- WatershedComponents[image,marker] finds basins only at the positions corresponding to foreground regions in a binary image marker.
- The target region marker can be any of the following:
-
markerimage a marker image {pos1,pos2,…} a list of positions - Positions posi are assumed to be in the standard image coordinate system.
- Typically, nonzero elements of marker are treated as seeds for the segmentation.
- The following options can be specified:
-
CornerNeighbors Automatic whether to include corner neighbors Method Automatic the method to use - Possible Method settings include:
-
"Watershed" morphological watershed method (Meyer) (default) "Basins" modified watershed algorithm (Beucher, Meyer) "Rainfall" gradient descent or rainfall algorithm (Osma-Ruiz) "Immersion" watershed immersion algorithm (Vincent–Soille) {"MinimumSaliency",t} gradient descent algorithm that merges adjacent basins if their minimum boundary height is less than t - The "Watershed" and "Immersion" methods return the watershed lines, represented as 0s in the label array.
- With the "MinimumSaliency" method, CornerNeighbors->False is always used. All other methods by default use CornerNeighbors->True.
Examples
open all close allBasic Examples (2)
Scope (3)
Mark two regions with a marker image:
WatershedComponents[[image], [image]]//ColorizeMark two regions with a list of positions:
WatershedComponents[[image], {{190, 180}, {190, 45}}]//ColorizeMark 3D regions and background with a binary mask:
i = [image];marker = [image];ws = WatershedComponents[i, marker];
Image3D[Colorize[SelectComponents[ws, "Count", 2]], Options[i, BoxRatios]]Options (3)
CornerNeighbors (2)
By default, diagonally adjacent pixels are considered as neighbors:
WatershedComponents[[image]]//ColorizeUse CornerNeighborsFalse to only consider horizontally and vertically adjacent pixels as neighbors:
WatershedComponents[[image], CornerNeighbors -> False]//ColorizeCornerNeighbors setting is ignored with Method->"MinimumSaliency":
img = [image];WatershedComponents[img, Method -> {"MinimumSaliency", .2}, CornerNeighbors -> True] == WatershedComponents[img, Method -> {"MinimumSaliency", .2}, CornerNeighbors -> False]Method (1)
Use a minimum saliency method to segment tiles in an image:
img = ColorNegate@[image];WatershedComponents[img, Method -> {"MinimumSaliency", .3}]//ColorizeLower saliency thresholds typically yield over-segmented results:
WatershedComponents[img, Method -> {"MinimumSaliency", 0}]//ColorizeUse higher saliency thresholds to merge similar neighboring components:
WatershedComponents[img, Method -> {"MinimumSaliency", .4}]//ColorizeApplications (8)
Separate overlapping components using the distance transform image:
img = [image];dt = ImageAdjust[ColorNegate[DistanceTransform[img]]]Visualize the separation of the overlapping components:
ImageMultiply[img, Image[WatershedComponents[dt], "Bit"]]Use watershed segmentation to separate overlapping 3D components:
image = [image];Compute distance transform of the volume:
iw = ColorNegate@ImageAdjust@DistanceTransform@image;Run watershed segmentation on the distance transform of a 3D volume and visualize the segmentation:
cw = WatershedComponents[iw];
cw *= ImageData[image];
Colorize[cw]Use 3D markers to enhance the segmentation:
markers = [image];cwm = WatershedComponents[iw, markers];
cwm *= ImageData[image];
Colorize[cwm]Binary image created from watershed ridges after removing the background:
Image[WatershedComponents[Threshold[[image], 0.18]] , "Bit"]img = [image];Use local maxima of smoothed data as markers:
markers = MaxDetect[GaussianFilter[img, 25], Padding -> 1];
HighlightImage[img, markers, Method -> {"DiskMarkers", 5}]Watershed segmentation using detected marker point:
WatershedComponents[GradientFilter[img, 3], markers]//ColorizePreprocessing the image by filling shallow regional maxima helps reduce over-segmentation:
img = [image];WatershedComponents[FillingTransform[ColorNegate[img], 0.2, Padding -> 1]]//ColorizeUse a combination of GradientFilter and FillingTransform to segment an image:
WatershedComponents[FillingTransform[GradientFilter[[image], 1], 0.05, Padding -> 1]]//ColorizeApproximate the Voronoi diagram of a set of points:
i = [image];Compute watershed transform of the distance transform of the image:
segs = WatershedComponents[DistanceTransform[i]];
Colorize[segs]Show the boundary of the components (Voronoi diagram) and the initial points:
HighlightImage[Image[segs, "Bit"], {Opacity[1], ColorNegate[i]}]Over-segmentation can be used in a creative way to finely texture the background in an image:
Image[WatershedComponents[Threshold[[image], 0.6]] , "Bit"]Properties & Relations (2)
The methods "Basins", "Rainfall", and "MinimumSaliency" assign all pixels to a catchment basin:
img = [image];Table[WatershedComponents[img, Method -> method]//Colorize, {method, {"Basins", "Rainfall", {"MinimumSaliency", 0}}}]The methods "Watershed" and "Immersion" compute watershed lines separating the components:
Table[WatershedComponents[img, Method -> method]//Colorize, {method, {"Watershed", "Immersion"}}]Use the default method to compute watershed lines separating the components:
WatershedComponents[img]//ColorizeTypically, plateau pixels are separated based on their proximity to regional minima:
img = [image];
Colorize[WatershedComponents[img], ImageSize -> 100]The method "MinimumSaliency" assigns all plateau pixels to the same component:
Colorize[WatershedComponents[img, Method -> {"MinimumSaliency", 0}], ImageSize -> 100]Possible Issues (1)
Typically, images do not have one regional minimum per component:
MinDetect[[image]]Watershed segmentation is conceptually using regional minima as markers:
WatershedComponents[[image]]//ColorizeComputing watershed on the gradient image typically gives a more desired segmentation:
g = GradientFilter[[image], 1]WatershedComponents[g]//ColorizeRelated Guides
Text
Wolfram Research (2010), WatershedComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/WatershedComponents.html (updated 2025).
CMS
Wolfram Language. 2010. "WatershedComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/WatershedComponents.html.
APA
Wolfram Language. (2010). WatershedComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WatershedComponents.html
BibTeX
@misc{reference.wolfram_2026_watershedcomponents, author="Wolfram Research", title="{WatershedComponents}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/WatershedComponents.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_watershedcomponents, organization={Wolfram Research}, title={WatershedComponents}, year={2025}, url={https://reference.wolfram.com/language/ref/WatershedComponents.html}, note=[Accessed: 12-June-2026]}