INNER CODE UNIT · Python

pick_background

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

def pick_background(colors: list[RGB], candidates: list[RGB] | None = None) -> RGB:
    """
    Pick the candidate farthest from the common colors.
    Used for choosing the color of pixels with alpha to avoid clashing
    with the actual colors in the image
    """
    background_color_candidates = candidates or DEFAULT_BACKGROUND_CANDIDATES

    if not colors:
        return (255, 255, 255)
    best, best_score = background_color_candidates[0], -1
    for color_candidate in background_color_candidates:
        score = min(_rgb_dist(color_candidate, c) for c in colors)
        if score > best_score:
            best, best_score = color_candidate, score
    return best

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…