mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
26 lines
559 B
Python
26 lines
559 B
Python
"""Mask extraction utilities."""
|
|
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
def extract_masked_region(
|
|
image: Image.Image,
|
|
mask: np.ndarray,
|
|
) -> Image.Image:
|
|
"""Extract masked region from image.
|
|
|
|
Args:
|
|
image: Original PIL Image.
|
|
mask: Binary mask as numpy array (True = keep).
|
|
|
|
Returns:
|
|
PIL Image with only the masked region visible.
|
|
"""
|
|
image_np = np.array(image.convert("RGB"))
|
|
|
|
# Apply mask.
|
|
masked_np = image_np * mask[:, :, np.newaxis]
|
|
|
|
return Image.fromarray(masked_np.astype(np.uint8))
|