MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / colorize_depth

Function colorize_depth

eval_code/recons/models/moge/utils/vis.py:7–18  ·  view source on GitHub ↗
(depth: np.ndarray, mask: np.ndarray = None, normalize: bool = True, cmap: str = 'Spectral')

Source from the content-addressed store, hash-verified

5
6
7def 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
21def colorize_depth_affine(depth: np.ndarray, mask: np.ndarray = None, cmap: str = 'Spectral') -> np.ndarray:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected