\HeaderA{watershed}{Watershed transformation and watershed based object detection}{watershed}
\keyword{manip}{watershed}
\begin{Description}\relax
Watershed transformation and watershed based object detection.
\end{Description}
\begin{Usage}
\begin{verbatim}
  watershed(x, tolerance=1, ext=1)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{Image} object or an array.
\item[\code{tolerance}] The minimum height of the object in the units of image
intensity between its highest point (seed) and the point where it
contacts another object (checked for every contact pixel). If the
height is smaller than the tolerance, the object will be combined with
one of its neighbors, which is the highest. Tolerance should be chosen
according to the range of \code{x}. Default value is 1, which 
is a reasonable value if \code{x} comes from \code{distmap}.
\item[\code{ext}] Radius of the neighborhood in pixels for the detection
of neighboring objects. Higher value smoothes out small objects. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The algorithm identifies and separates objects that stand out of the
background (zero). After the water fill, the source image
is flipped upside down and the resulting valleys (values with higher
intensities) are filled in first until another object or background is met.
The deepest valleys (pixels with highest intensity) become indexed first,
starting from 1.

The function \code{bwlabel} is a simpler, faster alternative to 
segment connected objects from binary images.
\end{Details}
\begin{Value}
An \code{Grayscale} \code{Image} object or an array, containing the
labelled version of \code{x}.
\end{Value}
\begin{Author}\relax
Oleg Sklyar, \email{osklyar@ebi.ac.uk}, 2007
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{bwlabel}{bwlabel}},  \code{\LinkA{propagate}{propagate}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x = readImage(system.file('images', 'shapes.png', package='EBImage'))
  x = x[110:512,1:130]
  if (interactive()) display(x, title='Binary')
  y = distmap(x)
  if (interactive()) display(normalize(y), title='Distance map')
  w = watershed(y)
  if (interactive()) display(normalize(w), title='Watershed')
\end{ExampleCode}
\end{Examples}

