\HeaderA{distmap}{Distance map transform}{distmap}
\begin{Description}\relax
Computes the distance map transform of a binary image.
The distance map is a matrix which contains for each pixel
the distance to its nearest background pixel.
\end{Description}
\begin{Usage}
\begin{verbatim}
  distmap(x, metric=c('euclidean', 'manhattan'))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{Image} object or an array.
\code{x} is considered as a binary image, whose pixels of value 0
are considered as background ones and other pixels as
foreground ones.
\item[\code{metric}] A character indicating which metric to use, L1 distance (\code{manhattan}) 
or L2 distance (\code{euclidean}). Default is \code{euclidean}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
A fast algorithm of complexity O(M*N*log(max(M,N))), where (M,N) are the
dimensions of \code{x}, is used to compute the distance map.
\end{Details}
\begin{Value}
An \code{Image} object or an array, with pixels
containing the distances to the nearest background points.
\end{Value}
\begin{Author}\relax
Gregoire Pau, \email{gpau@ebi.ac.uk}, 2008
\end{Author}
\begin{References}\relax
M. N. Kolountzakis, K. N. Kutulakos. Fast Computation of the Euclidean
Distance Map for Binary Images, Infor. Proc. Letters 43 (1992).
\end{References}
\begin{Examples}
\begin{ExampleCode}
   x = readImage(system.file("images", "shapes.png", package="EBImage"))
   if (interactive()) display(x)
   dx = distmap(x)
   if (interactive()) display(dx/10, title='Distance map of x')
\end{ExampleCode}
\end{Examples}

