MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / rescale_image_depthmap

Function rescale_image_depthmap

benchmark/utils/cropping.py:75–97  ·  view source on GitHub ↗

Jointly resize image + depthmap so that (W, H) >= output_resolution.

(image, depthmap, camera_intrinsics, output_resolution, force=True)

Source from the content-addressed store, hash-verified

73# ---- Crop/resize functions ----
74
75def rescale_image_depthmap(image, depthmap, camera_intrinsics, output_resolution, force=True):
76 """Jointly resize image + depthmap so that (W, H) >= output_resolution."""
77 image = ImageList(image)
78 input_resolution = np.array(image.size)
79 output_resolution = np.array(output_resolution)
80 if depthmap is not None:
81 assert tuple(depthmap.shape[:2]) == image.size[::-1]
82
83 assert output_resolution.shape == (2,)
84 scale_final = max(output_resolution / image.size) + 1e-8
85 if scale_final >= 1 and not force:
86 return (image.to_pil(), depthmap, camera_intrinsics)
87 output_resolution = np.floor(input_resolution * scale_final).astype(int)
88
89 image = image.resize(tuple(output_resolution), resample=lanczos if scale_final < 1 else bicubic)
90 if depthmap is not None:
91 depthmap = cv2.resize(depthmap, output_resolution, fx=scale_final,
92 fy=scale_final, interpolation=cv2.INTER_NEAREST)
93
94 camera_intrinsics = camera_matrix_of_crop(
95 camera_intrinsics, input_resolution, output_resolution, scaling=scale_final)
96
97 return image.to_pil(), depthmap, camera_intrinsics
98
99
100def crop_image_depthmap(image, depthmap, camera_intrinsics, crop_bbox):

Callers 1

deterministic_resizeFunction · 0.90

Calls 4

to_pilMethod · 0.95
resizeMethod · 0.95
ImageListClass · 0.70
camera_matrix_of_cropFunction · 0.70

Tested by

no test coverage detected