Computer Vision Lesson 23 – Background Subtraction | Dataplexa

Background Subtraction

Until now, we focused mainly on images. In this lesson, we move one step closer to video-based computer vision.

Background subtraction is a fundamental technique used to separate moving objects from a static or slowly changing background.


What Is Background Subtraction?

Background subtraction is the process of detecting foreground objects by comparing each video frame with a background model.

Anything that differs significantly from the background is treated as foreground.

In simple words:

  • Background = scene without important motion
  • Foreground = moving or newly appeared objects

Why Background Subtraction Is Important

Many real-world computer vision systems depend on detecting motion first.

Background subtraction is commonly used in:

  • Surveillance systems
  • Traffic monitoring
  • Human activity recognition
  • Sports analytics
  • Security cameras

Without background subtraction, every frame would need heavy processing.


Static Image vs Video Vision

This is an important conceptual shift.

  • Images → focus on shapes, colors, edges
  • Videos → focus on change over time

Background subtraction leverages the idea that the background stays mostly consistent while foreground changes.


Basic Working Principle

At a high level, background subtraction follows this logic:

  • Build a background model
  • Read a new frame
  • Compare frame with background
  • Extract differences

Pixels with large differences are labeled as foreground.


Background Model: What Does It Mean?

A background model represents what the scene usually looks like.

This model can be:

  • A single reference image
  • A running average of frames
  • A statistical model

More advanced models adapt over time to handle lighting changes and noise.


Simple Example (Conceptual)

Imagine a fixed camera in a hallway:

  • Walls and floor remain constant
  • People walking are new changes

Background subtraction highlights only the moving people, ignoring static elements.


Common Challenges

Background subtraction is not trivial. Real-world scenes introduce challenges:

  • Lighting changes
  • Shadows
  • Camera noise
  • Slow-moving objects
  • Background motion (trees, water)

Good algorithms must adapt to these issues.


Types of Background Subtraction Methods

Broadly, background subtraction techniques fall into:

  • Frame differencing
  • Statistical background models
  • Learning-based methods

We will explore each category step by step in upcoming lessons.


Frame Differencing (Basic Idea)

The simplest method is frame differencing:

  • Subtract current frame from previous frame
  • Threshold the difference

This works only for fast motion and fails with slow or stationary objects.


Why Adaptive Models Are Needed

In real environments:

  • Day becomes night
  • Lights turn on and off
  • Background slowly changes

Adaptive background models update themselves to stay accurate over time.


Where You Will Practice This

You will practice background subtraction using:

  • Python
  • OpenCV
  • Video files or webcam input

Recommended environments:

  • Jupyter Notebook
  • Google Colab
  • Local Python + OpenCV setup

Real-Life Applications

  • Intrusion detection
  • Vehicle counting
  • People tracking
  • Gesture recognition

Most real-time CV pipelines start with background subtraction.


Practice Questions

Q1. What is the main goal of background subtraction?

To separate moving foreground objects from a static or slowly changing background.

Q2. Why does simple frame differencing fail?

It cannot handle slow motion, lighting changes, or background variations.

Q3. Which environments are best for practicing video-based CV?

Jupyter Notebook, Google Colab, or local Python with OpenCV.

Homework / Observation Task

  • Watch CCTV footage online
  • Observe how moving objects are highlighted
  • Notice issues like shadows and lighting

Try to mentally map what is foreground and what should remain background.


Quick Recap

  • Background subtraction detects motion
  • Separates foreground from background
  • Essential for video-based vision
  • Foundation for tracking and detection

Next, we will study Template Matching, which focuses on locating known patterns in images.