We’re currently using napari for visualization of our 3D images and their segmentations. We’d also like to assess the quality of single cell measurements we made in those 3D images. Thus, I’m looking into ways to visualize measurements on segmented objects in napari.
We have one prototype working that generates a new intensity images for each measurement. That looks something like this:
The downside to our current approach is that it’s quite slow and memory intensive (needs to generate a new 3D image for each feature we want to visualize. I’ve been trying to implement a simpler approach to this by using custom colormaps. The idea being: I display my label image using the
napari.add_image() function and provide a colormap that maps each label value to the feature measurement. This would easily allow to generate dozens of colormaps for different features that could be checked with minimal computational overhead.
The issue I’m running into is creating colormaps and passing them to napari in a way that works in this case. I generate a colormap using the
napari/napari/utils/colormaps/colormap.py Colormap class that scaled from 0 to 1 (instead of e.g. 0 to ~1000 for my label images). To figure out how I need to pass the colormaps, I just gave random colors to each label (like one would to just display a label image). But napari then displays multiple consecutive labels (e.g. labels 35-37) in the same color.
Here’s a specific example:
This image has 748 unique labels, the max label is 761 (a few labels are missing). I generated a
napari.Colormap with either 749 colors (0 for background, 748 unique labels) with evenly interspaced colors or 762 (0 for background, 761 unique labels) with evenly interspaced colors.
When I use this colormap to display my label image, multiple labels get assigned the same color (first image: display using this colormap. Second image: Displaying as label image)
Is this a question of specifying the bins? There are more bins than are being displayed, almost like napari would only display ~1/3 of the bins (which would be ~256 bin => 8bit?)
Can colormaps be used for this kind of approach? If so, any idea why my test of just assigning random colors to each object isn’t working?
Eventually, I would want to display something related to feature measurements instead of random colors (see the first example image above). Is there a better way to achieve this or has anyone else tried to get there using colormaps?