Normalize depth map to uint8 images (white is closer).
(depth_map: torch.Tensor)
| 107 | |
| 108 | |
| 109 | def 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 | |
| 124 | def pytorch3d_rasterize( |
no outgoing calls
no test coverage detected