Image Processing Toolbox User's Guide Previous page   Next Page
watershed

Find image watershed regions

Syntax

Description

L = watershed(A) computes a label matrix identifying the watershed regions of the input matrix A, which can have any dimension. The elements of L are integer values greater than or equal to 0. The elements labeled 0 do not belong to a unique watershed region. These are called watershed pixels. The elements labeled 1 belong to the first watershed region, the elements labeled 2 belong to the second watershed region, and so on.

By default, watershed uses 8-connected neighborhoods for 2-D inputs and 26-connected neighborhoods for 3-D inputs. For higher dimensions, watershed uses the connectivity given by conndef(ndims(A),'maximal').

L = watershed(A,CONN) specifies the connectivity to be used in the watershed computation. CONN can have any of the following scalar values.

Value
Meaning
Two-dimensional connectivities
4
4-connected neighborhood
8
8-connected neighborhood
Three-dimensional connectivities
6
6-connected neighborhood
18
18-connected neighborhood
26
26-connected neighborhood

Connectivity can be defined in a more general way for any dimension by using for CONN a 3-by-3-by- ...-by-3 matrix of 0's and 1's. The 1-valued elements define neighborhood locations relative to the center element of CONN. Note that CONN must be symmetric about its center element.

Class Support

A can be a numeric or logical array of any dimension, and it must be nonsparse. The output array L is of class double.

Example

2-D Example

  1. Make a binary image containing two overlapping circular objects.
  2. Compute the distance transform of the complement of the binary image.
  3. Complement the distance transform, and force pixels that don't belong to the objects to be at -Inf.
  4. Compute the watershed transform and display it as an indexed image.

3-D Example

  1. Make a 3-D binary image containing two overlapping spheres.
  2. Compute the distance transform.
  3. Complement the distance transform, force nonobject pixels to be -Inf, and then compute the watershed transform.

Algorithm

watershed uses a variation of the Vincent and Soille algorithm [1]. For details of the variation, see toolbox/images/images/private/watershed_vs.h.

See Also

bwlabel, bwlabeln, bwdist, regionprops

Reference

[1]  Vincent, Luc, and Pierre Soille, "Watersheds in Digital Spaces: An Efficient Algorithm Based on Immersion Simulations," IEEE Transactions of Pattern Analysis and Machine Intelligence, Vol. 13, No. 6, June 1991, pp. 583-598.


Previous page  warp whitepoint Next page

© 1994-2005 The MathWorks, Inc.