4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 02:24:38 +08:00

colormaps: add "gray" (#2058)

* 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 <f-dy@users.noreply.github.com>
This commit is contained in:
Frédéric Devernay 2023-06-11 18:41:23 -07:00 committed by GitHub
parent f2fdd10d9b
commit d18588d5d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -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)

View File

@ -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