# Foreground detection

(Redirected from Background subtraction)
https://en.wikipedia.org/wiki/Background_subtraction

Foreground detection is one of the major tasks in the field of computer vision and image processing whose aim is to detect changes in image sequences. Background subtraction is any technique which allows an image's foreground to be extracted for further processing (object recognition etc.).

Many applications do not need to know everything about the evolution of movement in a video sequence, but only require the information of changes in the scene, because an image's regions of interest are objects (humans, cars, text etc.) in its foreground. After the stage of image preprocessing (which may include image denoising, post processing like morphology etc.) object localisation is required which may make use of this technique.

Foreground detection separates foreground from background based on these changes taking place in the foreground. It is a set of techniques that typically analyze video sequences recorded in real time with a stationary camera.

Background image and foreground image.

## Description

All detection techniques are based on modelling the background of the image, i.e. set the background and detect which changes occur. Defining the background can be very difficult when it contains shapes, shadows, and moving objects. In defining the background it is assumed that the stationary objects could vary in color and intensity over time.

Scenarios where these techniques apply tend to be very diverse. There can be highly variable sequences, such as images with very different lighting, interiors, exteriors, quality, and noise. In addition to processing in real time, systems need to be able to adapt to these changes.

A very good foreground detection system should be able to:

• Develop a background (estimate) model.
• Be robust to lighting changes, repetitive movements (leaves, waves, shadows), and long-term changes.

## Background subtraction

Background subtraction is a widely used approach for detecting moving objects in videos from static cameras. The rationale in the approach is that of detecting the moving objects from the difference between the current frame and a reference frame, often called "background image", or "background model". Background subtraction is mostly done if the image in question is a part of a video stream. Background subtraction provides important cues for numerous applications in computer vision, for example surveillance tracking or human pose estimation.[ citation needed]

Background subtraction is generally based on a static background hypothesis which is often not applicable in real environments. With indoor scenes, reflections or animated images on screens lead to background changes. Similarly, due to wind, rain or illumination changes brought by weather, static backgrounds methods have difficulties with outdoor scenes. [1]

## Temporal average filter

Temporal average filter example

The temporal average filter is a method that was proposed at the Velastin. This system estimates the background model from the median of all pixels of a number of previous images. The system uses a buffer with the pixel values of the last frames to update the median for each image.

To model the background, the system examines all images in a given time period called training time. At this time we only display images and will find the median, pixel by pixel, of all the plots in the background this time.

After the training period for each new frame, each pixel value is compared with the input value of funds previously calculated. If the input pixel is within a threshold, the pixel is considered to match the background model and its value is included in the pixbuf. Otherwise, if the value is outside this threshold pixel is classified as foreground, and not included in the buffer.

This method can not be considered very efficient because they do not present a rigorous statistical basis and requires a buffer that has a high computational cost.

## Conventional approaches

A robust background subtraction algorithm should be able to handle lighting changes, repetitive motions from clutter and long-term scene changes. [2] The following analyses make use of the function of V(x,y,t) as a video sequence where t is the time dimension, x and y are the pixel location variables. e.g. V(1,2,3) is the pixel intensity at (1,2) pixel location of the image at t = 3 in the video sequence.

### Using frame differencing

A motion detection algorithm begins with the segmentation part where foreground or moving objects are segmented from the background. The simplest way to implement this is to take an image as background and take the frames obtained at the time t, denoted by I(t) to compare with the background image denoted by B. Here using simple arithmetic calculations, we can segment out the objects simply by using image subtraction technique of computer vision meaning for each pixels in I(t), take the pixel value denoted by P[I(t)] and subtract it with the corresponding pixels at the same position on the background image denoted as P[B].

In mathematical equation, it is written as:

${\displaystyle P[F(t)]=P[I(t)]-P[B]}$

The background is assumed to be the frame at time t. This difference image would only show some intensity for the pixel locations which have changed in the two frames. Though we have seemingly removed the background, this approach will only work for cases where all foreground pixels are moving and all background pixels are static. [2] A threshold "Threshold" is put on this difference image to improve the subtraction (see Image thresholding).

${\displaystyle |P[F(t)]-P[F(t+1)]|>\mathrm {Threshold} }$

This means that the difference image's pixels' intensities are 'thresholded' or filtered on the basis of value of Threshold. [3] The accuracy of this approach is dependent on speed of movement in the scene. Faster movements may require higher thresholds.

### Mean filter

For calculating the image containing only the background, a series of preceding images are averaged. For calculating the background image at the instant t,

${\displaystyle B(x,y,t)={1 \over N}\sum _{i=1}^{N}V(x,y,t-i)}$

where N is the number of preceding images taken for averaging. This averaging refers to averaging corresponding pixels in the given images. N would depend on the video speed (number of images per second in the video) and the amount of movement in the video. [4] After calculating the background B(x,y,t) we can then subtract it from the image V(x,y,t) at time t = t and threshold it. Thus the foreground is

${\displaystyle |V(x,y,t)-B(x,y,t)|>\mathrm {Th} }$

where Th is threshold. Similarly we can also use median instead of mean in the above calculation of B(x,y,t).

Usage of global and time-independent thresholds (same Th value for all pixels in the image) may limit the accuracy of the above two approaches. [2]

### Running Gaussian average

For this method, Wren et al. [5] propose fitting a Gaussian probabilistic density function (pdf) on the most recent ${\displaystyle n}$ frames. In order to avoid fitting the pdf from scratch at each new frame time ${\displaystyle t}$, a running (or on-line cumulative) average is computed.

The pdf of every pixel is characterized by mean ${\displaystyle \mu _{t}}$ and variance ${\displaystyle \sigma _{t}^{2}}$ . The following is a possible initial condition (assuming that initially every pixel is background):

${\displaystyle \mu _{0}=I_{0}}$
${\displaystyle \sigma _{0}^{2}=\langle {\text{some default value}}\rangle }$

where ${\displaystyle I_{t}}$ is the value of the pixel's intensity at time ${\displaystyle t}$. In order to initialize variance, we can, for example, use the variance in x and y from a small window around each pixel.

Note that background may change over time (e.g. due to illumination changes or non-static background objects). To accommodate for that change, at every frame ${\displaystyle t}$, every pixel's mean and variance must be updated, as follows:

${\displaystyle \mu _{t}=\rho I_{t}+(1-\rho )\mu _{t-1}}$
${\displaystyle \sigma _{t}^{2}=d^{2}\rho +(1-\rho )\sigma _{t-1}^{2}}$
${\displaystyle d=|(I_{t}-\mu _{t})|}$

Where ${\displaystyle \rho }$ determines the size of the temporal window that is used to fit the pdf (usually ${\displaystyle \rho =0.01}$ ) and ${\displaystyle d}$ is the Euclidean distance between the mean and the value of the pixel.

Gaussian distribution for each pixel.

We can now classify a pixel as background if its current intensity lies within some confidence interval of its distribution's mean:

${\displaystyle {\frac {|(I_{t}-\mu _{t})|}{\sigma _{t}}}>k\longrightarrow {\text{foreground}}}$
${\displaystyle {\frac {|(I_{t}-\mu _{t})|}{\sigma _{t}}}\leq k\longrightarrow {\text{background}}}$

where the parameter ${\displaystyle k}$ is a free threshold (usually ${\displaystyle k=2.5}$ ). A larger value for ${\displaystyle k}$ allows for more dynamic background, while a smaller ${\displaystyle k}$ increases the probability of a transition from background to foreground due to more subtle changes.

In a variant of the method, a pixel's distribution is only updated if it is classified as background. This is to prevent newly introduced foreground objects from fading into the background. The update formula for the mean is changed accordingly:

${\displaystyle \mu _{t}=M\mu _{t-1}+(1-M)(I_{t}\rho +(1-\rho )\mu _{t-1})}$

where ${\displaystyle M=1}$ when ${\displaystyle I_{t}}$ is considered foreground and ${\displaystyle M=0}$ otherwise. So when ${\displaystyle M=1}$ , that is, when the pixel is detected as foreground, the mean will stay the same. As a result, a pixel, once it has become foreground, can only become background again when the intensity value gets close to what it was before turning foreground. This method, however, has several issues: It only works if all pixels are initially background pixels (or foreground pixels are annotated as such). Also, it cannot cope with gradual background changes: If a pixel is categorized as foreground for a too long period of time, the background intensity in that location might have changed (because illumination has changed etc.). As a result, once the foreground object is gone, the new background intensity might not be recognized as such anymore.

### Background mixture models

Mixture of Gaussians method approaches by modelling each pixel as a mixture of Gaussians and uses an on-line approximation to update the model. In this technique, it is assumed that every pixel's intensity values in the video can be modeled using a Gaussian mixture model. [6] A simple heuristic determines which intensities are most probably of the background. Then the pixels which do not match to these are called the foreground pixels. Foreground pixels are grouped using 2D connected component analysis. [6]

At any time t, a particular pixel (${\displaystyle x_{0},y_{0}}$)'s history is

${\displaystyle X_{1},\ldots ,X_{t}=\{V(x_{0},y_{0},i):1\leqslant i\leqslant t\}}$

This history is modeled by a mixture of K Gaussian distributions:

${\displaystyle P(X_{t})=\sum _{i=1}^{K}\omega _{i,t}N\left(X_{t}\mid \mu _{i,t},\Sigma _{i,t}\right)}$

where

${\displaystyle N\left(X_{t}\mid \mu _{it},\Sigma _{i,t}\right)={\dfrac {1}{(2\pi )^{D/2}}}{1 \over |\Sigma _{i,t}|^{1/2}}\exp \left(-{1 \over 2}(X_{t}-\mu _{i,t})^{T}\Sigma _{i,t}^{-1}\left(X_{t}-\mu _{i,t}\right)\right)}$

First, each pixel is characterized by its intensity in RGB color space. Then probability of observing the current pixel is given by the following formula in the multidimensional case

${\displaystyle P(X_{t})=\sum _{i=1}^{K}\omega _{i,t}\eta \left(X_{t}\,\mu _{i,t},\Sigma _{i,t}\right)}$

Where K is the number of distributions, ω is a weight associated to the ith Gaussian at time t and µ, Σ are the mean and standard deviation of said Gaussian respectively.

${\displaystyle \eta \left(X_{t}\,\mu _{i,t},\Sigma _{i,t}\right)={\dfrac {1}{(2/pi)^{n/2}\Sigma _{i,t}^{0.5}}}\exp \left(-{1 \over 2}(X_{t}-\mu _{i,t})\Sigma _{i,t}\left(X_{t}-\mu _{i,t}\right)\right)}$

Once the parameters initialization is made, a first foreground detection can be made then the parameters are updated. The first B Gaussian distribution which exceeds the threshold T is retained for a background distribution

${\displaystyle B=\operatorname {argmin} \left(\Sigma _{i-1}^{B}\omega _{i,t}>T\right)}$

The other distributions are considered to represent a foreground distribution. Then, when the new frame incomes at times ${\displaystyle t+1}$, a match test is made of each pixel. A pixel matches a Gaussian distribution if the Mahalanobis distance

${\displaystyle \left(\left(X_{t+1}-\mu _{t+1}\right)^{T}\Sigma _{i-1}^{b}\left(X_{t+1}-\mu _{t+1}\right)\right)^{0.5}

where k is a constant threshold equal to ${\displaystyle 2.5}$. Then, two cases can occur:

Case 1: A match is found with one of the k Gaussians. For the matched component, the update is done as follows [7]

${\displaystyle \sigma _{i,t+1}^{2}=\left(1-\rho \right)\sigma _{i,t}^{2}+\rho \left(X_{x+1}-\mu _{x+1}\right)\left(X_{x+1}-\mu _{x+1}\right)^{T}}$

Power and Schoonees [3] used the same algorithm to segment the foreground of the image

${\displaystyle \sigma _{i,t+1}=\left(1-\alpha \right)\omega _{i,t}+\alpha P\left(k\mid X_{t},\varphi \right)}$

The essential approximation to ${\displaystyle P\left(k\mid \ X_{t},\varphi \right)}$ is given by ${\displaystyle M_{k,t}}$ [8]

${\displaystyle M_{k,t}={\begin{cases}1&{\text{match}},\\0&{\text{otherwise}}.\end{cases}}}$

Case 2: No match is found with any of the ${\displaystyle K}$ Gaussians. In this case, the least probable distribution ${\displaystyle K}$ is replaced with a new one with parameters

${\displaystyle k_{i.t}={\text{low prior weight}}}$
${\displaystyle \mu _{i,t+1}=X_{t+1}}$
${\displaystyle \sigma _{i.t+1}^{2}={\text{large initial variance}}}$

Once the parameter maintenance is made, foreground detection can be made and so on. An on-line K-means approximation is used to update the Gaussians. Numerous improvements of this original method developed by Stauffer and Grimson [6] have been proposed and a complete survey can be found in Bouwmans et al. [7] A standard method of adaptive backgrounding is averaging the images over time, creating a background approximation which is similar to the current static scene except where motion occur.

## Surveys

Several surveys which concern categories or sub-categories of models can be found as follows:

• MOG background subtraction [7]
• Subspace learning background subtraction [9]
• Statistical background subtraction [10] [11]
• Fuzzy background subtraction [12]
• RPCA background subtraction [13] (See Robust principal component analysis for more details)
• Dynamic RPCA for background/foreground separation [14] (See Robust principal component analysis for more details)
• Decomposition into low-rank plus additive matrices for background/foreground Separation [15]
• Deep neural networks concepts for background subtraction [16]
• Traditional and recent approaches for background subtraction [17] [18]

## Applications

For more details, please see [19]

## References

1. ^ Piccardi, M. (2004). "Background subtraction techniques: A review" (PDF). 2004 IEEE International Conference on Systems, Man and Cybernetics. pp. 3099–3104. doi: 10.1109/icsmc.2004.1400815. ISBN  0-7803-8567-5.
2. ^ a b c Tamersoy, B. (September 29, 2009). "Background Subtraction – Lecture Notes" (PDF). University of Texas at Austin.
3. ^ Lu, N.; Wang, J.; Wu, Q.; Yang, L. (February 2012). An improved Motion Detection method for real time Surveillance. CiteSeerX .
4. ^ Benezeth, Y.; Jodoin, P.M.; Emile, B.; Laurent, H.; Rosenberger, C. (2008). "Review and Evaluation of Commonly-Implemented Background Subtraction Algorithms" (PDF). 2008 19th International Conference on Pattern Recognition (PDF). pp. 1–4. doi: 10.1109/ICPR.2008.4760998. ISBN  978-1-4244-2174-9.
5. ^ Wren, C.R.; Azarbayejani, A.; Darrell, T.; Pentland, A.P. (1997). "Pfinder: Real-time tracking of the human body" (PDF). IEEE Transactions on Pattern Analysis and Machine Intelligence. 19 (7): 780–785. doi: 10.1109/34.598236. hdl:.
6. ^ a b c Stauffer, C.; Grimson, W.E.L. (1999). "Adaptive background mixture models for real-time tracking" (PDF). Proceedings of the 1999 IEEE Computer Society Conference on Computer Vision and Pattern Recognition. pp. 246–252. doi: 10.1109/CVPR.1999.784637. ISBN  0-7695-0149-4.
7. ^ a b c Bouwmans, T.; El Baf, F.; Vachon, B. (November 2008). "Background Modeling using Mixture of Gaussians for Foreground Detection – A Survey". Recent Patents on Computer Science. 1 (3): 219–237. CiteSeerX . doi: 10.2174/2213275910801030219.
8. ^ Power, P.; Schoonees, J. (2002). "Understanding Background Mixture Models for Foreground Segmentation" (PDF). Proceedings Image and Vision Computing New Zealand 2002. pp. 267–271.
9. ^ Bouwmans, Thierry (November 2009). "Subspace Learning for Background Modeling: A Survey". Recent Patents on Computer Science. 2 (3): 223–234. doi: 10.2174/1874479610902030223.
10. ^ Chen, C. H. (2009). Handbook of Pattern Recognition and Computer Vision. pp. 181–199. doi: 10.1142/7297. ISBN  978-981-4273-38-1.
11. ^ Bouwmans, Thierry (September 2011). "Recent Advanced Statistical Background Modeling for Foreground Detection: A Systematic Survey". Recent Patents on Computer Science. 4 (3): 147–176. doi: 10.2174/1874479611104030147.
12. ^ Bouwmans, Thierry (2012). "Background Subtraction for Visual Surveillance". Handbook on Soft Computing for Video Surveillance. Chapman & Hall/CRC Cryptography and Network Security Series. pp. 103–138. ISBN  978-1-4398-5684-0.
13. ^ Bouwmans, Thierry; Zahzah, El Hadi (2014). "Robust PCA via Principal Component Pursuit: A review for a comparative evaluation in video surveillance". Computer Vision and Image Understanding. 122: 22–34. doi: 10.1016/j.cviu.2013.11.009.
14. ^ Vaswani, Namrata; Bouwmans, Thierry; Javed, Sajid; Narayanamurthy, Praneeth (2018). "Robust Subspace Learning: Robust PCA, Robust Subspace Tracking, and Robust Subspace Recovery". IEEE Signal Processing Magazine. 35 (4): 32–55. arXiv:. Bibcode: 2017arXiv171109492V. doi: 10.1109/MSP.2018.2826566.
15. ^ Bouwmans, Thierry; Sobral, Andrews; Javed, Sajid; Jung, Soon Ki; Zahzah, El-Hadi (2017). "Decomposition into low-rank plus additive matrices for background/Foreground separation: A review for a comparative evaluation with a large-scale dataset". Computer Science Review. 23: 1–71. arXiv:. doi: 10.1016/j.cosrev.2016.11.001.
16. ^ Vaswani, Namrata; Bouwmans, Thierry; Javed, Sajid; Narayanamurthy, Praneeth (2018). "Deep Neural Network Concepts for Background Subtraction: A Systematic Review and Comparative Evaluation". arXiv: [ cs.CV].
17. ^ Bouwmans, T. (2014-07-25). "Traditional Approaches in Background Modeling for Static Cameras". Background Modeling and Foreground Detection for Video Surveillance. CRC Press. ISBN  9781482205374.
18. ^ Bouwmans, T. (2014-07-25). "Recent Approaches in Background Modeling for Static Cameras". Background Modeling and Foreground Detection for Video Surveillance. CRC Press. ISBN  9781482205374.
19. ^ Bouwmans, T.; Garcia-Garcia, B. (2019). "Background Subtraction in Real Applications: Challenges, Current Models and Future Directions". arXiv: [ cs.CV].

### Comparisons

Several comparison/evaluation papers can be found in the literature:

### Books

• T. Bouwmans, F. Porikli, B. Horferlin, A. Vacavant, Handbook on "Background Modeling and Foreground Detection for Video Surveillance: Traditional and Recent Approaches, Implementations, Benchmarking and Evaluation", CRC Press, Taylor and Francis Group, June 2014. (For more information: http://www.crcpress.com/product/isbn/9781482205374)
• T. Bouwmans, N. Aybat, and E. Zahzah. Handbook on Robust Low-Rank and Sparse Matrix Decomposition: Applications in Image and Video Processing, CRC Press, Taylor and Francis Group, May 2016. (For more information: http://www.crcpress.com/product/isbn/9781498724623)