INNER CODE UNIT · Python

extract_and_scale_alpha

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

def extract_and_scale_alpha(image: Image.Image, scale_factor: int = 1) -> np.ndarray:
    """
    Extract alpha channel from an RGBA image and scale it.

    Args:
        image: RGBA PIL Image
        scale_factor: Integer scale factor for resizing (default 1 = no scaling)

    Returns:
        Numpy array of alpha channel values (uint8), scaled if scale_factor != 1
    """
    # Extract alpha channel from RGBA image
    alpha_channel = np.array(image.convert("RGBA"))[:, :, 3]

    # Scale alpha channel if needed
    if scale_factor != 1:
        alpha_img = Image.fromarray(alpha_channel, mode="L")
        new_size = (alpha_img.width * scale_factor, alpha_img.height * scale_factor)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…