Skip to content

fix(preprocess): eliminate MOG2 cold-start frame-0 whiteout - #22

Merged
Chouffe merged 1 commit into
mainfrom
fix/mog2-frame0-whiteout
Jul 15, 2026
Merged

Chouffe merged 1 commit into
mainfrom
fix/mog2-frame0-whiteout

Conversation

@Chouffe

@Chouffe Chouffe commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Problem

A fresh MOG2 subtractor runs per video, and it has no background model on
its first apply() — so frame 0 of every clip is flagged ~100% motion
and the red (motion) channel whites out, versus a steady-state motion
fraction of ~0.02–0.05.

Fix

Feed frame 0 to MOG2 so it still learns from it, but emit frame 1's
processed output in its place (duplicated), so the whiteout never reaches
the video while the frame count and index alignment stay intact. Applies to
both stabilize_and_preprocess_sonar_video.py and preprocess_sonar_video.py.

Why not "warm up MOG2 with the first N frames": re-emitting the warmup
frames double-counts them and corrupts the background model, inflating
steady-state foreground 30–100%. Priming without re-emitting is clean but
drops N frames. Duplicating frame 1 keeps every other frame untouched.

Verification

stabilize_and_preprocess CLI on small.mp4 (300 frames):

frames frame-0 red steady 10–50
before 302 1.0000 (whiteout) 0.0200
after 302 0.0080 0.0202

Frame count preserved; every frame ≥1 is byte-identical by construction
(MOG2 is fed the same 0,1,2… sequence). ruff clean, 99 tests pass.

Refs: lumax-eco/sonar-smolt-detection#107

MOG2 has no background model on its first apply(), so frame 0 of every
clip is flagged ~100% motion and the red channel whites out. Feed frame 0
to MOG2 so it still learns from it, but emit frame 1's processed output in
its place (duplicated) so the whiteout never reaches the video while the
frame count and index alignment stay intact.

Applies to both stabilize_and_preprocess_sonar_video.py and
preprocess_sonar_video.py.

Refs: lumax-eco/sonar-smolt-detection#107
@Chouffe
Chouffe merged commit bd1d026 into main Jul 15, 2026
2 checks passed
@Chouffe
Chouffe deleted the fix/mog2-frame0-whiteout branch July 15, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant