""" Image properties provider. Delegates color-profile guessing and dominant-color extraction to cores.vision.color — no duplicated k-means logic. """ from __future__ import annotations import numpy as np from config.settings import Settings, settings as _default_settings from cores.vision import guess_color_profile, dominant_colors from pipeline.feature_extraction import PipelineOutput from providers.base import BaseProvider, ProviderCapability class ImagePropertiesProvider(BaseProvider): name = "image_properties" capability = ProviderCapability.IMAGE_ANALYSIS def __init__(self, settings: Settings | None = None) -> None: super().__init__(settings=settings or _default_settings) def is_available(self) -> bool: return True def _run(self, pipeline_output: PipelineOutput) -> tuple[dict, dict]: img: np.ndarray = pipeline_output.image h, w = img.shape[:2] channels = img.shape[2] if img.ndim == 3 else 1 aspect = round(w / h, 4) if h > 0 else 0 megapixels = round((w * h) / 1_000_000, 4) profile = guess_color_profile(img) colors = dominant_colors(img, k=5) raw = { "width": w, "height": h, "channels": channels, "aspect_ratio": aspect, "megapixels": megapixels, "color_profile": profile, "dominant_colors": colors, } normalized = { "quality_score": None, "width": w, "height": h, "channels": channels, "color_profile": profile, "dominant_colors": colors, "aspects": {"aspect_ratio": aspect, "megapixels": megapixels}, } return raw, normalized