From 5b2531923708f25eac245e1f61807dc5ca5d5cc4 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:23:00 -0500 Subject: [PATCH 1/2] use napari.utils.colormaps.ensure_colormap to use a napari colormap if it exists, else create a custom one --- src/napari_omero/plugins/loaders.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/napari_omero/plugins/loaders.py b/src/napari_omero/plugins/loaders.py index a4c3cb1..c81d620 100644 --- a/src/napari_omero/plugins/loaders.py +++ b/src/napari_omero/plugins/loaders.py @@ -3,7 +3,7 @@ import dask.array as da from dask.delayed import delayed from napari.types import LayerData -from vispy.color import Colormap +from napari.utils.colormaps import ensure_colormap from napari_omero.utils import PIXEL_TYPES, lookup_obj, parse_omero_url, timer from napari_omero.widgets import QGateWay @@ -78,9 +78,10 @@ def get_omero_metadata(image: ImageWrapper) -> dict: colors = [] for ch in channels: # use current rendering settings from OMERO - color = ch.getColor().getRGB() - color = [r / 256 for r in color] - colors.append(Colormap([[0, 0, 0], color])) + color = ch.getColor().getHtml() + # if the colormap exists in napari, use it + # otherwise, create a custom colormap + colors.append(ensure_colormap("#" + color)) contrast_limits = [[ch.getWindowStart(), ch.getWindowEnd()] for ch in channels] From 4f10b8b5995c3d025071df1d51ff4b76d4163e20 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:26:03 -0500 Subject: [PATCH 2/2] workaround for napari issue --- src/napari_omero/plugins/loaders.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/napari_omero/plugins/loaders.py b/src/napari_omero/plugins/loaders.py index c81d620..2b5911f 100644 --- a/src/napari_omero/plugins/loaders.py +++ b/src/napari_omero/plugins/loaders.py @@ -79,9 +79,15 @@ def get_omero_metadata(image: ImageWrapper) -> dict: for ch in channels: # use current rendering settings from OMERO color = ch.getColor().getHtml() - # if the colormap exists in napari, use it - # otherwise, create a custom colormap - colors.append(ensure_colormap("#" + color)) + # work around a napari bug https://github.com/napari/napari/issues/7504 + if color == "000000": + colors.append(ensure_colormap("gray_r")) + if color == "FFFFFF": + colors.append(ensure_colormap("gray")) + else: + # if the colormap exists in napari, use it + # otherwise, create a custom colormap + colors.append(ensure_colormap("#" + color)) contrast_limits = [[ch.getWindowStart(), ch.getWindowEnd()] for ch in channels]