This section describes functions that help build a statistical model of a background. This model can be used to subtract the background from an image.
Here, the term “background” stands for a set of motionless image pixels
that is, pixels that do not belong to any object, moving in front of the camera. The definition of background can vary if considered in other techniques of object extraction. For example, if the depth map of the scene can be obtained, for example, with the help of stereo, background can be determined as static parts of the scene that are located far enough from the camera.
The simplest background model assumes that every background pixel brightness varies independently, according to normal distribution. To calculate the characteristics of the background, several dozens of frames, as well as their squares, can be accumulated. That is, for every pixel location we find the sum of pixel values in this location
is the number of collected frames, and standard deviation as
After that, the pixel in a certain pixel location within a certain frame is considered as belonging to a moving object, if the condition
abs(p(x, y) - m(x, . y)) < C * stddev(x, y)
is a constant, is met. If
is equal to 3, it satisfies the “three sigmas” rule. To obtain such background model, objects should be put away from the camera for a few seconds, so that the whole image from the camera represents the subsequent background observation.
Adapting the background differencing model to changes in lighting conditions and background scenes, for example, when the camera moves or an object passes behind the front object, can improve the described technique.
The mean brightness can be calculated through replacing the simple average with the running average found by using the function