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:
-
- 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)
Watershed segmentation of an image with two regional minima:
Visualize the segmentation:
Watershed segmentation of a 3D image:
Scope (3)
Mark two regions with a marker image:
Mark two regions with a list of positions:
Mark 3D regions and background with a binary mask:
Options (3)
CornerNeighbors (2)
By default, diagonally adjacent pixels are considered as neighbors:
Use CornerNeighbors False to only consider horizontally and vertically adjacent pixels as neighbors:
CornerNeighbors setting is ignored with Method->"MinimumSaliency":
Method (1)
Use a minimum saliency method to segment tiles in an image:
Lower saliency thresholds typically yield over-segmented results:
Use higher saliency thresholds to merge similar neighboring components:
Applications (8)
Separate overlapping components using the distance transform image:
Visualize the separation of the overlapping components:
Use watershed segmentation to separate overlapping 3D components:
Compute distance transform of the volume:
Run watershed segmentation on the distance transform of a 3D volume and visualize the segmentation:
Use 3D markers to enhance the segmentation:
Binary image created from watershed ridges after removing the background:
Heart chamber segmentation:
Use local maxima of smoothed data as markers:
Watershed segmentation using detected marker point:
Preprocessing the image by filling shallow regional maxima helps reduce over-segmentation:
Use a combination of GradientFilter and FillingTransform to segment an image:
Approximate the Voronoi diagram of a set of points:
Compute watershed transform of the distance transform of the image:
Show the boundary of the components (Voronoi diagram) and the initial points:
Over-segmentation can be used in a creative way to finely texture the background in an image:
Properties & Relations (2)
The methods "Basins", "Rainfall", and "MinimumSaliency" assign all pixels to a catchment basin:
The methods "Watershed" and "Immersion" compute watershed lines separating the components:
Use the default method to compute watershed lines separating the components:
Typically, plateau pixels are separated based on their proximity to regional minima:
The method "MinimumSaliency" assigns all plateau pixels to the same component:
Possible Issues (1)
Typically, images do not have one regional minimum per component:
Watershed segmentation is conceptually using regional minima as markers:
Computing watershed on the gradient image typically gives a more desired segmentation:
Neat Examples (1)
Solve a maze puzzle using watershed transform:
Related 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_2025_watershedcomponents, author="Wolfram Research", title="{WatershedComponents}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/WatershedComponents.html}", note=[Accessed: 17-November-2025]}
BibLaTeX
@online{reference.wolfram_2025_watershedcomponents, organization={Wolfram Research}, title={WatershedComponents}, year={2025}, url={https://reference.wolfram.com/language/ref/WatershedComponents.html}, note=[Accessed: 17-November-2025]}