MCPcopy
hub / github.com/nerfstudio-project/gsplat / apply_float_colormap

Function apply_float_colormap

examples/utils.py:176–197  ·  view source on GitHub ↗

Convert single channel to a color img. Args: img (torch.Tensor): (..., 1) float32 single channel image. colormap (str): Colormap for img. Returns: (..., 3) colored img with colors in [0, 1].

(img: torch.Tensor, colormap: str = "turbo")

Source from the content-addressed store, hash-verified

174
175
176def apply_float_colormap(img: torch.Tensor, colormap: str = "turbo") -> torch.Tensor:
177 """Convert single channel to a color img.
178
179 Args:
180 img (torch.Tensor): (..., 1) float32 single channel image.
181 colormap (str): Colormap for img.
182
183 Returns:
184 (..., 3) colored img with colors in [0, 1].
185 """
186 img = torch.nan_to_num(img, 0)
187 if colormap == "gray":
188 return img.repeat(1, 1, 3)
189 img_long = (img * 255).long()
190 img_long_min = torch.min(img_long)
191 img_long_max = torch.max(img_long)
192 assert img_long_min >= 0, f"the min value is {img_long_min}"
193 assert img_long_max <= 255, f"the max value is {img_long_max}"
194 return torch.tensor(
195 colormaps[colormap].colors, # type: ignore
196 device=img.device,
197 )[img_long[..., 0]]
198
199
200def apply_depth_colormap(

Callers 6

apply_depth_colormapFunction · 0.85
viewer_render_fnFunction · 0.85
evalMethod · 0.85
_viewer_render_fnMethod · 0.85
viewer_render_fnFunction · 0.85
_viewer_render_fnMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…