\HeaderA{thresh}{Adaptive thresholding}{thresh}
\keyword{manip}{thresh}
\begin{Description}\relax
Thresholds an image using a moving rectangular window.
\end{Description}
\begin{Usage}
\begin{verbatim}
  thresh(x, w=5, h=5, offset=0.01)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{Image} object or an array.
\item[\code{w, h}] Width and height of the moving rectangular window.
\item[\code{offset}] Thresholding offset from the averaged value.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function returns the binary image resulting from the comparison
between an image and its filtered version with a rectangular window.
It is equivalent of doing \code{\{f = matrix(1, nc=2*w+1, nr=2*h+1) ; f=f/sum(f) ; x>(filter2(x, f)+offset)\}} 
but slightly faster. The function \code{filter2} provides hence more 
flexbility than \code{thresh}.
\end{Details}
\begin{Value}
An \code{Image} object or an array, containing the transformed version
of \code{x}.
\end{Value}
\begin{Author}\relax
Oleg Sklyar, \email{osklyar@ebi.ac.uk},  2005-2007
\end{Author}
\begin{SeeAlso}\relax
\code{filter2}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x = readImage(system.file('images', 'nuclei.tif', package='EBImage'))
  if (interactive()) display(x)
  y = thresh(x, 10, 10, 0.05)
  if (interactive()) display(y)
\end{ExampleCode}
\end{Examples}

