INNER CODE UNIT · Python
flat
KennethJAllen/proper-pixel-art · proper_pixel_art/colors.py:148
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.
If at least ``majority_fraction`` of the cell's pixels are transparent
(alpha < alpha_threshold), the cell becomes fully transparent (0,0,0,0);
otherwise it takes the most common RGB color at full opacity (R,G,B,255).