(depth: np.ndarray, mask: np.ndarray = None, normalize: bool = True, cmap: str = 'Spectral')
| 5 | |
| 6 | |
| 7 | def colorize_depth(depth: np.ndarray, mask: np.ndarray = None, normalize: bool = True, cmap: str = 'Spectral') -> np.ndarray: |
| 8 | if mask is None: |
| 9 | depth = np.where(depth > 0, depth, np.nan) |
| 10 | else: |
| 11 | depth = np.where((depth > 0) & mask, depth, np.nan) |
| 12 | disp = 1 / depth |
| 13 | if normalize: |
| 14 | min_disp, max_disp = np.nanquantile(disp, 0.001), np.nanquantile(disp, 0.99) |
| 15 | disp = (disp - min_disp) / (max_disp - min_disp) |
| 16 | colored = np.nan_to_num(matplotlib.colormaps[cmap](1.0 - disp)[..., :3], 0) |
| 17 | colored = np.ascontiguousarray((colored.clip(0, 1) * 255).astype(np.uint8)) |
| 18 | return colored |
| 19 | |
| 20 | |
| 21 | def colorize_depth_affine(depth: np.ndarray, mask: np.ndarray = None, cmap: str = 'Spectral') -> np.ndarray: |
nothing calls this directly
no outgoing calls
no test coverage detected