mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-13 04:25:32 +08:00
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
"""Image saving utilities for simulation verification output."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
|
|
def save_room_view(
|
|
output_dir: Path,
|
|
room_id: str,
|
|
view_idx: int,
|
|
image: Image.Image,
|
|
) -> Path:
|
|
"""Save a single room view image to disk.
|
|
|
|
Args:
|
|
output_dir: Base output directory.
|
|
room_id: Room identifier string.
|
|
view_idx: Zero-based view index within the room.
|
|
image: PIL Image to save.
|
|
|
|
Returns:
|
|
Path where the image was saved.
|
|
"""
|
|
room_dir = output_dir / room_id
|
|
room_dir.mkdir(parents=True, exist_ok=True)
|
|
path = room_dir / f"view_{view_idx:03d}.png"
|
|
image.convert("RGB").save(path, format="PNG")
|
|
return path
|
|
|
|
|
|
def save_object_image(
|
|
output_dir: Path,
|
|
room_id: str,
|
|
obj_id: str,
|
|
view_idx: int,
|
|
mask_idx: int,
|
|
image: Image.Image,
|
|
) -> Path:
|
|
"""Save a masked object image to disk.
|
|
|
|
Args:
|
|
output_dir: Base output directory.
|
|
room_id: Room identifier string.
|
|
obj_id: Object identifier string.
|
|
view_idx: Zero-based view index.
|
|
mask_idx: Zero-based mask index within the view.
|
|
image: PIL Image to save.
|
|
|
|
Returns:
|
|
Path where the image was saved.
|
|
"""
|
|
room_dir = output_dir / room_id
|
|
room_dir.mkdir(parents=True, exist_ok=True)
|
|
path = room_dir / f"{obj_id}_view{view_idx:03d}_mask{mask_idx:02d}.png"
|
|
image.convert("RGB").save(path, format="PNG")
|
|
return path
|