INNER CODE UNIT · Python

get_opaque_cell_color

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

def get_opaque_cell_color(cell_pixels: np.ndarray) -> RGBA:
    """
    cell_pixels: shape (height_cell, width_cell, 3), dtype=uint8
    returns the most frequent RGB tuple in the cell_pixels block, with 255 in fourth entry for opaque alpha.
    """
    flat = list(map(tuple, cell_pixels.reshape(-1, 3)))
    cell_color = Counter(flat).most_common(1)[0][0]
    return (*cell_color, 255)


def get_cell_color_with_alpha(
    cell_pixels: np.ndarray,
    cell_alpha: np.ndarray,
    alpha_threshold: int = ALPHA_THRESHOLD,
    majority_fraction: float = _DEFAULTS.transparency_majority_fraction,
) -> RGBA:
    """
    Select a representative color for a quantized cell, honoring transparency.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…