\HeaderA{filter2}{2D Convolution Filter}{filter2}
\begin{Description}\relax
Filters an image using the fast 2D FFT convolution product.
\end{Description}
\begin{Usage}
\begin{verbatim}
  filter2(x, filter)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] An \code{Image} object or an array.
\item[\code{filter}] An \code{Image} object or an array, with odd spatial
dimensions. Must contain only one frame.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Linear filtering is useful to perform low-pass filtering (to blur
images, remove noise...) and high-pass filtering (to detect
edges, sharpen images). The function \code{makeBrush} is useful to
generate filters.

Data is reflected around borders.

If \code{x} contains multiple franes, the filter will be applied one each frame.
\end{Details}
\begin{Value}
An \code{Image} object or an array, containing the filtered version
of \code{x}.
\end{Value}
\begin{Author}\relax
Gregoire Pau, \email{gpau@ebi.ac.uk}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{makeBrush}{makeBrush}}, \code{\LinkA{convolve}{convolve}}, \code{\LinkA{fft}{fft}}, \code{\LinkA{blur}{blur}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  x = readImage(system.file("images", "lena-color.png", package="EBImage"))
  if (interactive()) display(x, title='Lena')

  ## Low-pass disc-shaped filter
  f = makeBrush(21, shape='disc', step=FALSE)
  if (interactive()) display(f, title='Disc filter')
  f = f/sum(f)
  y = filter2(x, f)
  if (interactive()) display(y, title='Filtered lena')

  ## High-pass Laplacian filter
  la = matrix(1, nc=3, nr=3)
  la[2,2] = -8
  y = filter2(x, la)
  if (interactive()) display(y, title='Filtered lena')
\end{ExampleCode}
\end{Examples}

