In background subtraction, we subtract the unnecessary background from the image and take only the vital information of the foreground object. The input for background subtraction is usually a video stream or a series of images.
The goal of background subtraction is to separate the background from the object and generate a foreground mask. This mask is of the exact dimensions as the original image, with ones in the place of the foreground object and zeros in the background.
The background in the original image or a video stream frame is the background model.
As shown in the figure above, we generate a foreground mask that extracts just the object under consideration when applied to the original image. There're several methods to perform background subtraction. Each of them has its pros and cons. The most common and simple one is frame difference.
In the frame difference method, we take a previous frame from our input and an absolute difference from the current frame. Here, we assume that the previous frame is our background model (static background), and the current frame has the object we want to focus on. In this way, the static background will be zero.
It would be an ideal case if the background stayed static. But with the object's movement in the frame, we may have a difference between light and shadows. Therefore, we apply
Its mathematical representation is:
It's helpful to use the frame difference method for the below reasons:
Frame difference is a fairly simple method, however, there're drawbacks that are as follows:
We can use the background subtraction in:
Free Resources