mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
feat(simulator): add image saving utilities for verification
This commit is contained in:
@@ -4,6 +4,7 @@ from .feature_extractor import (
|
||||
extract_single_image_feature,
|
||||
infer_vector_dim,
|
||||
)
|
||||
from .image import numpy_to_pil
|
||||
|
||||
__all__ = [
|
||||
"get_device",
|
||||
@@ -11,4 +12,5 @@ __all__ = [
|
||||
"infer_vector_dim",
|
||||
"extract_single_image_feature",
|
||||
"extract_batch_features",
|
||||
"numpy_to_pil",
|
||||
]
|
||||
|
||||
21
mini-nav/utils/image.py
Normal file
21
mini-nav/utils/image.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Image conversion utilities."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def numpy_to_pil(rgb: np.ndarray) -> Image.Image:
|
||||
"""Convert an RGB numpy array to a PIL Image.
|
||||
|
||||
Handles arrays with 4 channels (RGBA) by dropping the alpha channel.
|
||||
|
||||
Args:
|
||||
rgb: Numpy array of shape (H, W, C) with dtype uint8 or compatible.
|
||||
|
||||
Returns:
|
||||
PIL Image in RGB mode.
|
||||
"""
|
||||
rgb3 = rgb[..., :3] if rgb.shape[-1] > 3 else rgb
|
||||
return Image.fromarray(rgb3.astype(np.uint8))
|
||||
Reference in New Issue
Block a user