INNER CODE UNIT · Python

_is_majority_transparent

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

def _is_majority_transparent(
    opaque_count: int,
    total_count: int,
    majority_fraction: float = _DEFAULTS.transparency_majority_fraction,
) -> bool:
    """Cell is transparent if at least ``majority_fraction`` of pixels are transparent."""
    return opaque_count <= total_count * (1 - majority_fraction)


def _rgb_dist(a: RGB, b: RGB) -> int:
    """Naive color distance"""
    dr, dg, db = a[0] - b[0], a[1] - b[1], a[2] - b[2]
    return dr**2 + dg**2 + db**2


def top_opaque_colors(
    img: Image.Image,
    alpha_threshold: int,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…