computes the watershed transform of image, returning the result as a matrix in which positive integers label the catchment basins.

WatershedComponents[image, marker]
uses a binary image marker to indicate regions where basins may be created.

Details and OptionsDetails and Options

  • WatershedComponents[image] finds basins at each regional minimum in image.
  • WatershedComponents[image, marker] finds basins only at the positions corresponding to foreground regions in a binary image marker.
  • In WatershedComponents[image, marker], marker can be given either as an image, a graphics object, or a list of points in the standard image coordinate system, where x runs from 0 to width and y runs from 0 to height, and position corresponds to the bottom-left corner of the image.
  • Typically, nonzero elements of marker are treated as seeds for the segmentation.
  • In the label matrix returned by WatershedComponents, zeros represent positions that do not belong to any foreground component.
  • WatershedComponents works with binary, grayscale, and other images.
  • For multichannel images, WatershedComponents operates on the intensity averaged over all channels.
  • WatershedComponents[image, Method->method] specifies the method to use to compute the watershed transform.
  • The default setting is Method->"Watershed". Possible settings include:
  • "Watershed"morphological watershed method (Meyer)
    "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 and methods return the watershed lines, represented as 0s in the label matrix.
  • With the method, only four direct neighbors are considered adjacent. All other methods treat all eight pixels surrounding a given pixel as adjacent.
  • With a setting CornerNeighbors->False, WatershedComponents finds a segmentation based only on directly connected pixels.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Use watershed contours to illustrate the trabecular bone structure:

Click for copyable input

Watershed segmentation of an image:

Click for copyable input

Watershed segmentation of a gradient image:

Click for copyable input
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »