# public documents.sextractor_doc

## [/] [detect_background.tex] - Rev 25

\section{Background estimation}
\label{chap:backest}
The value measured at each pixel is a function of the sum of a background''
signal and light coming from the objects of interest. To be able to detect
the faintest of these objects and also to measure accurately their fluxes, one needs
to have an accurate estimate of the background level in any place of the \index{image} image,
a \emph{background map}.  Strictly speaking, there should be one \index{background map} background map per
object, that is, what would the \index{image} image look like if that object was absent.
But, at least for detection, we may start by assuming that most discrete sources do not
overlap too severely, which is generally the case for high galactic latitude fields.

To construct the \index{background map} background map, {\sc SExtractor} makes a first pass through the pixel
data, computing an estimator for the \index{local background} local background in each mesh of a grid
that covers the whole frame.
The background estimator is a combination of $\kappa\,\sigma$ clipping and \index{mode} mode estimation,
similar to the one employed in Stetson's \index{DAOPHOT} DAOPHOT program (see e.g. Da Costa 1992).
Briefly, the \index{local background} local background histogram is clipped iteratively until convergence at
$\pm 3\sigma$ around its \index{median} median; \gam{Is the factor 3 configurable?} if $\sigma$ is changed by less than 20\% during that process,
we consider that the field is not crowded and we simply take the \index{mean} mean of the clipped histogram
as a value for the background; otherwise we estimate the \index{mode} mode with:
$$\label{eq:mode} \mbox{Mode} = 2.5 \times \mbox{Median} - 1.5 \times \mbox{Mean}$$
This expression is different from the usual approximation
$$\mbox{Mode} = 3 \times \mbox{Median} - 2 \times \mbox{Mean}$$
(e.g. Kendall and Stuart 1977), but was found to be more accurate with our clipped
distributions, from the simulations we made. Fig. \ref{fig:modevsmean} shows that the expression of
the \index{mode} mode above is considerably less affected\footnote{Obviously in some very unfavorable cases
(like small meshes falling on bright \index{stars} stars), it leads to totally inaccurate results.} by \index{crowding} crowding
than a simple clipped \index{mean} mean --- like the one used in \index{FOCAS} FOCAS (Jarvis and Tyson 1981)
or by Infante (1987) --- but is $\approx 30\%$ noisier.
% For this reason
This is why
we revert to the clipped
\index{mean} mean in non-crowded fields.

%---------------------------------- Fig.modevsmean  --------------------------------
\begin{figure}[htbp]
\centerline{\includegraphics[width=12cm]{ps/modevsmean.ps}}
\caption{
Simulations of $32\times32$ pixels background meshes polluted by random Gaussian profiles.
The true background lies at 0 ADU. While being slightly noisier, the clipped Mode''
gives a more robust estimate than a clipped Mean in crowded regions.
}
\label{fig:modevsmean}
\end{figure}

Once the grid is set up, a \index{median} median filter can be applied to suppress possible
local overestimations due to bright \index{stars} stars. \gam{But sometimes the user will
want to have the bright star be part of the background!} The resulting \index{background map} background map is then simply a (natural)
bicubic-spline \index{interpolation} interpolation between the meshes of the grid.
In parallel with the making of the \index{background map} background map, an \emph{RMS background map}, that is, a map of the
background noise in the \index{image} image is produced. It will be used if the {\tt WEIGHT\_TYPE} parameter is
set different from {\tt NONE} (see \S\ref{chap:weighttype}).

\subsection{Configuration parameters and tuning}.
The choice of the mesh size ({\tt BACK\_SIZE}) is very important.
If it is too small, the background estimation is affected by the presence of objects and
random noise. Most importantly, part of the flux of the most extended
objects can be absorbed into the \index{background map} background map. If the mesh size is too large,
it cannot reproduce the small scale variations of the background. Therefore
a good compromise has to be found by the user. Typically, for reasonably
sampled \index{image} images, a width\footnote{{\sc SExtractor} offers the
possibility of rectangular background meshes; but it is advised to use
square ones, except in some very special cases (rapidly varying background
in one direction for example).} of 32 to 256 pixels works well. The user has
some control over the \index{background map} background map by specifying the size
of the \index{median} median filter ({\tt BACK\_FILTERSIZE}). A width
and height of 1 \index{mean} means that no filtering will be
applied to the background grid. Usually a size of $3\times3$ is enough, but it
may be necessary to use larger dimensions, especially to compensate, in part, for
small background mesh sizes, or in the case of large artefacts in the \index{image} images.
Median filtering also helps reducing possible \index{ringing} ringing effects of the bicubic-spline
around bright features. In some specific cases it might be desirable to \index{median} median-filter
only background meshes whose original values exceed some \index{threshold} threshold above the filtered-value.
This differential \index{threshold} threshold is set by the {\tt BACK\_FILTERTHRESH} parameter, in ADUs.
It is important to note that all {\tt BACK\_} configuration parameters also affect the
background-RMS map.

By default, the computed \index{background map} background map is automatically subtracted
from the input \index{image} image.  But there are some situations where it is more
appropriate to subtract a {\em constant} from the \index{image} image (e.g., images
where the background noise distribution is strongly skewed).  The {\tt
BACK\_TYPE} configuration parameter (set by default to AUTO'') can
be switched to {\tt MANUAL} to allow for the value specified by the
{\tt BACK\_VALUE} parameter to be subtracted from the input
\index{image} image. The default value is 0.

\gam{Describe {\tt MINIBACK}}
\label{chap:miniback}

\subsection{CPU cost}.
The background estimation operation can take a considerable time on the largest \index{image} images,
e.g. a few minutes minutes for a $32000\times32000$ frame on a 2GHz
processor.
\gam{Update time?}