MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / visualize_depth_map

Function visualize_depth_map

motion_rep/motion_checker.py:109–121  ·  view source on GitHub ↗

Normalize depth map to uint8 images (white is closer).

(depth_map: torch.Tensor)

Source from the content-addressed store, hash-verified

107
108
109def visualize_depth_map(depth_map: torch.Tensor) -> np.ndarray:
110 """Normalize depth map to uint8 images (white is closer)."""
111 B, C, H, W = depth_map.shape
112 assert C == 1, "Depth map should have a single channel."
113 max_depth = torch.amax(depth_map, dim=[0, 2, 3], keepdim=True)
114 mask = depth_map != -1
115 depth_map = depth_map.clone()
116 depth_map[~mask] = float("inf")
117 min_positive_depth = torch.amin(depth_map, dim=[0, 2, 3], keepdim=True)
118 normalized_depth_map = (max_depth - depth_map) / (max_depth - min_positive_depth)
119 normalized_depth_map *= mask.float()
120 normalized_depth_map = (normalized_depth_map * 255).clamp(0, 255).byte()
121 return normalized_depth_map.squeeze(1).cpu().numpy()
122
123
124def pytorch3d_rasterize(

Callers 2

render_and_save_overlayFunction · 0.85
render_and_saveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected