4-seasons: protect night frames from grey filter with brightness floor

A stddev-only filter would wrongly drop near-black night frames.
Now only skips a frame when BOTH stddev < GREY_MIN AND mean brightness
> GREY_DARK_FLOOR (default 30/255).  Night frames are dark so they
always pass; bad-signal grey frames are mid-bright so they are caught.

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
Claude
2026-04-22 16:17:22 +00:00
parent 4aeee6b3d5
commit ec8eb7aebf
2 changed files with 20 additions and 7 deletions
+8 -3
View File
@@ -92,6 +92,7 @@ mapfile -t all_images < <(find "$image_dir" -type f -name "*.jpg" | sort)
# SEASONS_GREY_STDDEV_MIN=0 (default) disables the grey filter.
# Set to e.g. 5 in sky-cam.conf to drop uniform grey frames (bad-signal captures).
GREY_MIN="${SEASONS_GREY_STDDEV_MIN:-0}"
GREY_DARK_FLOOR="${SEASONS_GREY_DARK_FLOOR:-30}" # frames darker than this are never skipped
images=(); bad=0; grey=0
for img in "${all_images[@]}"; do
# Empty or unreadable
@@ -106,10 +107,14 @@ for img in "${all_images[@]}"; do
echo "WARNING: skipping corrupt frame: $(basename "$img")"
((bad++)) || true; continue
fi
# Optional: skip uniform-grey bad-signal frames (low pixel standard deviation)
# Optional: skip uniform-grey bad-signal frames.
# A frame is bad-signal if it is BOTH uniform (low stddev) AND not dark.
# Night frames are dark so they pass even with low stddev.
if [ "$GREY_MIN" != "0" ] && command -v convert &>/dev/null; then
stddev=$(convert "$img" -colorspace Gray -format "%[fx:int(standard_deviation*255)]" info: 2>/dev/null || echo "255")
if [ "${stddev:-255}" -lt "$GREY_MIN" ]; then
read -r stddev mean < <(convert "$img" -colorspace Gray \
-format "%[fx:int(standard_deviation*255)] %[fx:int(mean*255)]" \
info: 2>/dev/null || echo "255 128")
if [ "${stddev:-255}" -lt "$GREY_MIN" ] && [ "${mean:-0}" -gt "$GREY_DARK_FLOOR" ]; then
((grey++)) || true; continue
fi
fi
+12 -4
View File
@@ -257,13 +257,21 @@ AUDIO_BITRATE=192k # montage-mvt.sh — music track on movement
# ── Frame validation (4-seasons.sh) ──────────────────────────────────────────
# Corrupt or empty frames (e.g. first frame after a camera reconnect) are always
# skipped automatically via ffprobe.
# skipped automatically via ffprobe. No config needed.
#
# SEASONS_GREY_STDDEV_MIN: also skip uniform-grey frames caused by a bad RTSP
# signal. These are valid JPEGs but contain a near-solid grey image.
# Value is the minimum pixel standard deviation on a 0255 scale.
# 0 = disabled (default). Try 510 if your camera produces grey frames on reconnect.
# signal (valid JPEGs, but near-solid grey — no real image content).
# A frame is only skipped when BOTH conditions hold:
# 1. pixel standard deviation (0255) is below SEASONS_GREY_STDDEV_MIN
# 2. mean brightness (0255) is above SEASONS_GREY_DARK_FLOOR
# This keeps genuine night frames (dark + low stddev) while dropping
# bad-signal grey frames (mid-bright + low stddev).
#
# SEASONS_GREY_STDDEV_MIN=0 disables the filter entirely (default).
# Try 510 if your camera produces solid-grey frames on reconnect.
# Requires ImageMagick (convert) to be installed.
SEASONS_GREY_STDDEV_MIN=0
SEASONS_GREY_DARK_FLOOR=30 # frames with mean brightness below this are always kept
# ── Montage attribution overlay ───────────────────────────────────────────────
# A translucent bar across the top of each movement montage, naming the