Replies: 2 comments 6 replies
-
Hello @HripsimeS ! We have a layer for visualizing label image that renders the different label values as different colors that sounds like it might be useful for your use case. See the docs here. While I don't think we have a built in function to convert images from your image layout to a label image, I have pasted a snippet below that should do the conversion ( I haven't tested it, but I think it should work). Is this what you had in mind? # assuming image is ordered CZYX
label_image_shape = image.shape[1:4]
label_image = np.zeros_like(label_image_shape, dtype=int)
for label_index, channel_image in enumerate(image):
if label_index == 0:
# skip the background channel
pass
label_image[channel_image.astype(bool)] = label_index
# make the viewer
viewer = napari.Viewer()
viewer.add_labels(label_image)
# call napari.run() if running from a script
napari.run() |
Beta Was this translation helpful? Give feedback.
-
Hey @HripsimeS! Are your labels ever overlapping, or are they guaranteed to never intersect? If they overlap, you will not be able to use a single In the data you provided, they do not overlap, so for this particular case, you're in luck :) Here's some code that should work: import nibabel
import napari
import numpy as np
# load image as integers
image = 'dataset6_CLINIC_0090_data_seg.nii.gz'
data = nibabel.load(image).get_data().astype(int)
# multiply each label by an increasing number
data_multiplied = data * np.arange(data.shape[-1])
# sum along the channel axis. Since they don't overlap, you get 0 if no label was found, or the
# label's index where a label is found
data_labels = data_multiplied.sum(axis=-1)
v = napari.Viewer(ndisplay=3)
v.add_labels(data_labels) labels.mp4A side note: you may want to consider using a more efficient storage for the data. You're using |
Beta Was this translation helpful? Give feedback.
-
Dear Napari team,
I have a segmentation output NIFITI file which has 5 channels (0, 1, 2, 3, 4). 0 is a background and (1,2,3,4) are the labels/classes that was predicted. With Napari I can do a nice 3D rendering of separate labels, but I would like to see all 4 labels on the same rendering with different colors. Is there any method on Napari to convert 5 dimensional image to one dimensional to be able to see all labels on the same 3D rendering?
In attached you can find a Total slices for Axis 1 (depth of my image) and Total slices for Axis 0 (number of my labels)
Beta Was this translation helpful? Give feedback.
All reactions