The notebook can be found here: https://colab.research.google.com/drive/1npzkUZijAVJWhkhBYbzSFOigD468_YAT#scrollTo=DTSpNgqPavqK
This project implements an approach for change detection between consecutive video frames by leveraging SLIC superpixel segmentation instead of noisy, slow pixel-by-pixel comparisons.
The core idea is to first segment each image into meaningful regions (superpixels) and then compare these regions' features and positions to determine if a change has occurred.
The system compares two consecutive frames,
The SLIC (Simple Linear Iterative Clustering) algorithm is applied to each frame to cluster similar, nearby pixels into superpixels.
-
Gaussian Blurring: A slight Gaussian blur (
$\sigma=1$ ) is applied before segmentation to reduce noise and smooth small texture details, improving superpixel quality. -
Parameters:
-
n_segments: The desired number of superpixels. The value affects the size and precision of regions. -
compactness($m$ ): Balances color similarity ($d_{lab}$ ) against spatial proximity ($d_{xy}$ ), controlling the shape of the superpixels.$$D = \sqrt{d_{lab}^2 + m \times d_{xy}^2}$$
-
For every superpixel in a frame, a 4-dimensional feature vector is computed, along with its centroid (spatial center).
A superpixel in frame
-
Spatial Proximity Filtering: Only candidates in
$t+1$ whose centroid is within a maximum spatial distance of the superpixel's centroid in$t$ are considered. - Feature Distance Matching: Among the spatial candidates, the best match is the one with the minimum feature distance.
-
Change Criteria: A superpixel in
$t$ is declared "changed" if:- It has no spatially close candidates in
$t+1$ . - The feature distance to its best match is greater than a threshold.
- It has no spatially close candidates in
-
New Object Detection (Extension): Superpixels in
$t+1$ that were never matched to any superpixel from$t$ are considered "new regions" (e.g., a new object entering the scene) and are also flagged as changed.
A binary mask is created from all "changed" superpixels (including "new regions"). The changes are then visualized on both frames
- Displaying the boundaries of all superpixels.
- Filling the detected changed regions with a semi-transparent red overlay.
- Fast Motion: If an object moves significantly such that its centroid displacement exceeds
max_spatial_dist, the matching will fail, and it will be flagged as a change/new object. - Sudden Appearance/Disappearance: While partially handled by the "new region" detection, sudden object appearance/disappearance can still create segmentation mismatches.
- Segmentation Jitter: Small changes in the SLIC superpixel boundaries between frames can occasionally lead to mismatches, especially with object deformation.
Integrate Optical Flow:
The current method assumes minimal movement between frames. A significant improvement would be to use Optical Flow (e.g., Lucas-Kanade) to estimate the motion of the pixels between frames
-
Predict Motion: Move the centroid of a superpixel in
$t$ according to the flow to better predict its location in$t+1$ . - Improve Matching: Perform the spatial proximity check and feature matching on the predicted location, allowing for successful matching even with significant object motion.