"""Lightweight quality heuristics before or after standardization.""" from __future__ import annotations from typing import Any import numpy as np def short_side_ratio(bgr: np.ndarray) -> float: h, w = bgr.shape[:2] if h <= 0 or w <= 0: return 0.0 return float(min(h, w) / max(h, w)) def passes_quality( bgr: np.ndarray, *, min_short_side_ratio: float = 0.35, ) -> bool: """Reject extremely elongated crops / bad aspect (proxy for truncation).""" return short_side_ratio(bgr) >= min_short_side_ratio def annotate_quality(row: dict[str, Any], bgr: np.ndarray, cfg_min_ratio: float) -> None: r = short_side_ratio(bgr) row["aspect_min_over_max"] = r row["quality_ok"] = r >= cfg_min_ratio