INNER CODE UNIT · Python

dominant_rgb_by_binning

KennethJAllen/proper-pixel-art · proper_pixel_art/colors.py:182

def dominant_rgb_by_binning(
    rgb_pixels: np.ndarray, bin_size: int = _DEFAULTS.bin_size
) -> RGB:
    """
    Find the dominant color of ``rgb_pixels`` using offset binning.

    RGB space is split into bins of width ``bin_size`` along two grids: a
    standard grid and one shifted by half a bin. Whichever grid yields the
    larger single bin wins, and the median color of that bin is returned. The
    two grids avoid boundary artifacts: colors straddling one grid's boundary
    fall together in the other.

    For <=3 pixels, binning is skipped and the single value (or median) is
    returned directly.

    Args:
        rgb_pixels: shape (N, 3), dtype=uint8 - flat array of RGB values.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…