Skip to content

Commit cbd5de3

Browse files
committed
fix(cli/assemble-brick-expert): fix depth image saving
1 parent 49f255a commit cbd5de3

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

python/bricksim/cli/assemble_brick_expert.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
import cv2
7+
import numpy as np
78
import torch
89
from PIL import Image
910

@@ -100,18 +101,24 @@ def _save_camera_images(
100101
"""Save camera observation images for one rollout step.
101102
102103
Args:
103-
images_obs: Non-concatenated image observation group keyed by term name.
104-
save_camera_dir: Directory where PNG images are written.
104+
images_obs: Non-concatenated camera observation group keyed by term name.
105+
RGB images are saved as PNG files. Other arrays, such as float32 depth
106+
maps in meters, are saved as compressed NPZ files with key ``image``.
107+
save_camera_dir: Directory where camera observations are written.
105108
step: Rollout step index used in output filenames.
106109
107110
Returns:
108111
None.
109112
"""
110113
for obs_name, image_tensor in images_obs.items():
111114
image = image_tensor[0].detach().cpu()
112-
output_path = save_camera_dir / f"step_{step:06d}_{obs_name}.png"
113115
output_image = image.contiguous().numpy()
114-
Image.fromarray(output_image).save(output_path)
116+
if image.ndim == 3 and image.shape[-1] == 3 and image.dtype == torch.uint8:
117+
output_path = save_camera_dir / f"step_{step:06d}_{obs_name}.png"
118+
Image.fromarray(output_image).save(output_path)
119+
else:
120+
output_path = save_camera_dir / f"step_{step:06d}_{obs_name}.npz"
121+
np.savez_compressed(output_path, image=output_image)
115122

116123

117124
def _show_camera_images(images_obs: dict[str, torch.Tensor]) -> None:

0 commit comments

Comments
 (0)