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

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.
  • The following options can be specified:
  • CornerNeighborsAutomaticwhether to include corner neighbors
    MethodAutomaticthe 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 (VincentSoille)
    {"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.

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
Introduced in 2010