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