fix(preprocess): eliminate MOG2 cold-start frame-0 whiteout - #22
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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% motionand 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.pyandpreprocess_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_preprocessCLI onsmall.mp4(300 frames):Frame count preserved; every frame ≥1 is byte-identical by construction
(MOG2 is fed the same 0,1,2… sequence).
ruffclean, 99 tests pass.Refs: lumax-eco/sonar-smolt-detection#107