feat: exposure detection (over/underexposed)

This commit is contained in:
Ferdinand
2026-04-07 13:19:57 +02:00
parent cf19b8fd7e
commit bac279294f
2 changed files with 37 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import cv2
import numpy as np
from PIL import Image
def is_blurry(path: str, threshold: float = 100.0) -> bool:
@@ -9,3 +10,20 @@ def is_blurry(path: str, threshold: float = 100.0) -> bool:
return False
variance = cv2.Laplacian(img, cv2.CV_64F).var()
return bool(variance < threshold)
def _mean_brightness(path: str) -> float:
"""Durchschnittliche Helligkeit eines Bildes (0-255)."""
img = Image.open(path).convert("L")
arr = np.array(img, dtype=np.float32)
return float(arr.mean())
def is_overexposed(path: str, threshold: float = 240.0) -> bool:
"""Gibt True zurueck, wenn das Bild ueberbelichtet ist."""
return _mean_brightness(path) > threshold
def is_underexposed(path: str, threshold: float = 30.0) -> bool:
"""Gibt True zurueck, wenn das Bild unterbelichtet ist."""
return _mean_brightness(path) < threshold