From d18588d5d43fafa87aa819cdb3dc5b4e09f05549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Devernay?= <124616582+f-dy@users.noreply.github.com> Date: Sun, 11 Jun 2023 18:41:23 -0700 Subject: [PATCH] colormaps: add "gray" (#2058) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * colormaps: remove useless "pca" choice, add "gray" - The "pca" choice didn't work when applied to a single-channel image (it crashed the viewer), and it's applied by default to any image of more than 3 channels, where the colormap choice is ignore anyway. - Add the trivial "gray" colormap, useful to eg extract accumulation. * colormaps.py: re-add "pca" * control_panel: don't show the "pca" option either --------- Co-authored-by: Frédéric Devernay --- nerfstudio/utils/colormaps.py | 4 +++- nerfstudio/viewer/server/control_panel.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nerfstudio/utils/colormaps.py b/nerfstudio/utils/colormaps.py index 0e09c0bfd..d772d40b4 100644 --- a/nerfstudio/utils/colormaps.py +++ b/nerfstudio/utils/colormaps.py @@ -24,7 +24,7 @@ from torch import Tensor from nerfstudio.utils import colors -Colormaps = Literal["default", "turbo", "viridis", "magma", "inferno", "cividis", "pca"] +Colormaps = Literal["default", "turbo", "viridis", "magma", "inferno", "cividis", "gray", "pca"] @dataclass(frozen=True) @@ -104,6 +104,8 @@ def apply_float_colormap(image: Float[Tensor, "*bs 1"], colormap: Colormaps = "v colormap = "turbo" image = torch.nan_to_num(image, 0) + if colormap == "gray": + return image.repeat(1, 1, 3) image_long = (image * 255).long() image_long_min = torch.min(image_long) image_long_max = torch.max(image_long) diff --git a/nerfstudio/viewer/server/control_panel.py b/nerfstudio/viewer/server/control_panel.py index 456e3598c..7039b61c3 100644 --- a/nerfstudio/viewer/server/control_panel.py +++ b/nerfstudio/viewer/server/control_panel.py @@ -361,7 +361,7 @@ def _get_colormap_options(dimensions: int, dtype: type) -> List[Colormaps]: if dimensions == 3: colormap_options = ["default"] if dimensions == 1 and dtype == torch.float: - colormap_options = [c for c in list(get_args(Colormaps)) if c != "default"] + colormap_options = [c for c in list(get_args(Colormaps)) if c not in ("default", "pca")] if dimensions > 3: colormap_options = ["pca"] return colormap_options