Motion and background modelling
Video is a signal over time. Frame differencing and running-average background models separate what moves from what stays still — with real failure modes.
A still image is a snapshot; a video is a function of time. Motion is what changes between consecutive frames, and detecting it is the first step of almost every video analytics pipeline: count people, flag intrusions, measure traffic. The naive idea — subtract one frame from the next — almost works, and understanding exactly why it fails is the whole lesson.
The problem is that "what moves" is not the same as "what differs". A stationary object that turns on a light differs without moving; a person in camouflage moves without differing much. The right target is a background model: an estimate of the scene without the things you care about, against which each frame is compared.
What is the background?
There is no single background — only a model of it that you maintain over time. Run a slow exponential average of the pixels and it converges to the scene's persistent appearance. A pixel far from that model right now is foreground. Everything hard about the problem is in how you update the model so that genuine changes get absorbed and moving things do not.
Scrub through the clip and switch methods; the current frame, the background estimate and the foreground mask are all computed live.
A bright disc moves across a noisy scene. Compare frame differencing, a running average, and a foreground-gated background update.
current frame
background model
foreground mask
foreground pixels
45
method
selective
Real per-pixel arithmetic on a synthetic clip. Frame differencing only flags change and leaves nothing at rest; the plain running average smears the moving object into the background; the selective update is the preprocessing half of Stauffer–Grimson-style mixture-of-Gaussians background modelling.
Three models, three failures
Let be the frame at time and the background estimate.
- Frame differencing. Foreground where . Simple and fast, but only flags change: a slow-moving object almost vanishes and a stationary one leaves nothing behind.
- Running average. Update , then threshold . The background adapts, but a moving object is averaged into it, leaving a smeared ghost and a persistent trail.
- Selective (gated) update. Update the background only where the pixel is not currently foreground. Moving objects stop polluting the model, at the cost that a real scene change (a parked car, a switched-off lamp) is absorbed only once it stops being foreground.
From running average to mixtures
A single mean per pixel struggles when the scene has multiple stable appearances — leaves that sway, water that ripples, monitors that flicker. Stauffer and Grimson model each pixel with a mixture of Gaussians, assigning each new value to the component it fits best and updating that component's weight, mean and variance. A pixel is background if it matches a high-weight, low-variance component. This handles small persistent motions and adapts its sensitivity per pixel.
What breaks every background model
- Illumination change. A cloud passing changes every pixel at once.
- Shadows. The dark region a person casts moves with them and is persistently mislabelled unless colour or gradient cues remove it.
- Camera motion. If the camera moves, nothing in the image is background in the model's frame; you must first stabilise using the matching techniques of the previous chapter.
- Intermittent motion. Objects that stop for a while get absorbed into the background and disappear as foreground when they move again.
The model and the foreground are coupled
You need a background model to decide the foreground, but the standard update needs the foreground decision to avoid polluting the model. Get that loop wrong and the background either absorbs the objects you are trying to detect or stops adapting entirely. Every practical system tunes the learning rate and threshold against this trade-off.
Illustrative vs real
The widget uses a synthetic 24×18 clip with a single moving disc and a simple pixel value, so the arithmetic is transparent. Real systems work on colour or gradients, use multiple Gaussians per pixel, add shadow suppression and morphological cleanup, and often precede all of it with optical flow or ego-motion compensation. The detections above feed the trackers and activity recognisers of the next lesson.
Check yourself
Eduspheria wiki · Applied AI, Video analytics
0 / 5 answered
From the exam paper
Modeled on NITJ AI-604, End-Sem May 2025
0 / 5 answered
Where next: once motion is isolated, the next question is what the motion means — recognising activities and behaviours over time.