\HeaderA{floodFill}{Filling matrix data with flood fill algorithm}{floodFill}
\aliasA{fillHull}{floodFill}{fillHull}
\aliasA{fillHull,IndexedImage-method}{floodFill}{fillHull,IndexedImage.Rdash.method}
\aliasA{floodFill,array-method}{floodFill}{floodFill,array.Rdash.method}
\keyword{file}{floodFill}
\begin{Description}\relax
Functions to fill regions in images and matrices/arrays and fill holes in 
indexed objects.
\end{Description}
\begin{Usage}
\begin{verbatim}
  ## S4 method for signature 'array':
  floodFill(x, pt, col, tolerance=1e-3, ...)
  ## S4 method for signature 'IndexedImage':
  fillHull(x, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{\LinkA{array}{array}}-like object (e.g. \code{\LinkA{Image}{Image.Rdash.class}}) 
to be filled. For \code{fillHull} this must be an instance of \code{\LinkA{IndexedImage}{IndexedImage.Rdash.class}}.
\item[\code{pt}] An integer of 2 values for \code{x-y} coordinates of the point where
fill starts. 
\item[\code{col}] A value for the fill color, supposedly in the same storage mode as 
\code{x}. If \code{x} is an image \code{col} will be converted to the 
corresponding storage mode using the \code{\LinkA{channel}{channel}} function, and thus
can be a character value specifying the color in X11 mode.
\item[\code{tolerance}] Color tolerance used during the fill. 
\item[\code{...}] Reserved. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If no color is specified, the color under the coordinates of \code{pt} is used 
(this only has sense if tolerance is not zero). The flood fill is implemented
using the fast scan line algorithm. It is assumed that \code{floodFill} is
run either on matrices of single-framed images. If the latter is not the case,
only the first frame will be modified!

\code{fillHull} files holes in objects of \code{\LinkA{IndexedImage}{IndexedImage.Rdash.class}}'s.
\end{Details}
\begin{Value}
A copy of \code{x} with the fill applied.
\end{Value}
\begin{Author}\relax
Gregoire Pau, Oleg Sklyar; 2007
\end{Author}
\begin{SeeAlso}\relax
\code{
  \LinkA{Image}{Image.Rdash.class}, \LinkA{Image}{Image.Rdash.class}
}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
if (interactive()) {
  data(imageWithHoles)

  display(x, main="Original image")
  display(floodFill(x,c(5,5),tolerance=0.2))
  display(floodFill(x,c(40,40),tolerance=0.2))

  mask = x
  mask[mask>0.3]=1
  mask[mask<=0.3]=0

  y = floodFill(mask,c(40,40),2)
  class(y) = "IndexedImage"
  display(y, main="Indexed mask with holes")
  
  y = fillHull(y)
  display(y, main="Indexed mask without holes")

  rgb = channel(normalize(y), "rgb")
  rgb = floodFill(rgb, c(1,1), "red")
  rgb = floodFill(rgb, c(50,50), "blue")
  rgb = floodFill(rgb, c(150,150), "green")
  display(rgb)
}\end{ExampleCode}
\end{Examples}

