INNER CODE UNIT · Python
get_cell_color_with_alpha
KennethJAllen/proper-pixel-art · proper_pixel_art/colors.py:153
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).
Args:
cell_pixels: shape (height, width, 3), dtype=uint8 (RGB from quantized image).
cell_alpha: shape (height, width), dtype=uint8 (alpha from the original image).
"""
total_pixels = cell_alpha.size