Background Subtraction

Comparison of Grimson’s background subtraction method with Gaussian and simple background subtraction

As a project for one of my courses, I have implemented some background subtraction techniques, along with the code and demo, I have tried to explain my approach for coding them.

Simple Background Subtraction

Considering first image as the background.
For each next frame, calculate the difference between the current image and the background image.
Threshold used is the average of maximum and minimum values of all the available images.
All values greater than the threshold are considered as foreground.

Gaussian Background Subtraction

Considering first image as the mean.
For all the remaining images, new mean is calculated using: (1-alpha)*mean + alpha*image
New variance is calculated using: (alpha)*(subtract(image,mean)**2) + (1-alpha)*(var)
Subtract mean from the current image.
Using 2.5 as threshold to replace mean and variance with the newly computed values.
Similarly, values greater than 2.5 are considered as foreground.

Grimson Method

Because variance becomes negative after some time because of norm-pdf function so convert those indices values which are near zero to some higher values.
Calculate standard deviation.
Get values for the inequality test to get indexes of fitting indexes.
Finding those indexes where values of T are less than most probable gaussian and those where sum of most probable and medium probable is greater than T and most probable is less than T.
Finding those indices where a particular pixel value fits at least one of the gaussian.
Update variance and mean value of the matched indices of all three gaussians.
Update least probable gaussian for those pixel values which do not match any of the gaussian.
Normalise omega.
Finding omega by sigma for ordering of the gaussian.
Getting index order for sorting omega by sigma.
Sorting mean,variance and omega.
Get background from index2 and index3.


First row is the input.
Second row is the simple background subtraction.
Third row is the gaussian background subtraction.
Fourth row is the grimson method.