4-seasons: replace size-rejection with 1MB fast-skip for grey filter

File size can't reliably reject bad frames (200KB can be good or bad).
Remove SEASONS_MIN_FRAME_BYTES.  Instead, the grey/green uniform-colour
filter (SEASONS_GREY_STDDEV_MIN) now skips the expensive ImageMagick
check for files above SEASONS_LARGE_FRAME_BYTES (default 1 MB) since
those are always good.  Only sub-1MB files get the content check, making
the filter practical on days with 40k+ images.

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
Claude
2026-04-23 02:34:26 +00:00
parent a9faa63cd9
commit 98dcf23687
2 changed files with 28 additions and 17 deletions
+18 -12
View File
@@ -95,11 +95,14 @@ trap cleanup EXIT
mapfile -t all_images < <(find "$image_dir" -type f -name "*.jpg" | sort)
# Validate each frame: skip empty files, corrupt JPEGs, and optionally grey/uniform frames.
# 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).
# Validate each frame: skip empty files and optionally uniform-colour bad-signal frames.
# SEASONS_GREY_STDDEV_MIN=0 (default) disables the content check entirely.
# When enabled, large files (> SEASONS_LARGE_FRAME_BYTES, default 1 MB) are trusted
# as good without running the expensive ImageMagick check — only sub-1MB frames
# are inspected. This keeps the filter fast even on days with 40k+ images.
GREY_MIN="${SEASONS_GREY_STDDEV_MIN:-0}"
GREY_DARK_FLOOR="${SEASONS_GREY_DARK_FLOOR:-30}" # frames darker than this are never skipped
GREY_DARK_FLOOR="${SEASONS_GREY_DARK_FLOOR:-30}"
LARGE_BYTES="${SEASONS_LARGE_FRAME_BYTES:-1048576}" # files above this skip content check
images=(); bad=0; grey=0
for img in "${all_images[@]}"; do
# Skip empty or unreadable files (0-byte writes from camera reconnects)
@@ -107,15 +110,18 @@ for img in "${all_images[@]}"; do
echo "WARNING: skipping empty/missing frame: $(basename "$img")"
((bad++)) || true; continue
fi
# 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.
# Optional: skip uniform-colour bad-signal frames (green, grey, etc.).
# Only runs ImageMagick on files below SEASONS_LARGE_FRAME_BYTES — large files
# are always good and skip the check entirely.
if [ "$GREY_MIN" != "0" ] && command -v convert &>/dev/null; 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
fsize=$(stat -c%s "$img" 2>/dev/null || echo 0)
if [ "$fsize" -lt "$LARGE_BYTES" ]; 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
fi
images+=("$img")