Visualizing channel data present in czi file in napari

Hi All,

This is a follow up to my previous post here

I’ve read the contents of a czi file

import napari
from aicsimageio import AICSImage
from aicsimageio.writers import OmeTiffWriter

img = AICSImage("file.czi")
first_channel_data = img.get_image_data("ZYX", C=1, S=0, T=0)
print(img.get_channel_names())

with napari.gui_qt():
    viewer = napari.Viewer()
    layer = viewer.add_image(img.data)

Now I see all 3 channels, I would like to know if there is a way to specify which channel to
visualize? Or how to display the channel name while visualizing?

I could get the channel names like this: print(img.get_channel_names())

For instance, now I see
image
I can navigate to different channels but I couldn’t find a way to view the channel names.

Even if I try specifying a name,
viewer.add_image(img.data, name='Ch1-T2')

I find all channels.

1 Like

layer = viewer.add_image(img.data)

Here you’re adding the entire image, whereas I think you want to be doing

layer = viewer.add_image(first_channel_data)

instead to view only the first channel.

Now, you can simply add the name parameter into add_image to view the channel name as well.

If you want to view each individual channel, labelled with the channel names you can use something like this:

import napari
from aicsimageio import AICSImage

img = AICSImage(filename)
channel_names = img.get_channel_names()

with napari.gui_qt():
    viewer = napari.Viewer()
    for c, c_name in enumerate(channel_names):
        viewer.add_image(img.get_image_data("ZYX", C=c, S=0, T=0), 
                         name=c_name)

From there, you can turn each channel on or off to view them separately, and also play around with the other parameters such as the colormap, blending etc for each layer

2 Likes

In the output I could only see a binary image.
image

But these channels are stained. May I know how to view the colors?

The image doesn’t look binary, I think you’re just using the gray colormap so the image is grayscale. You can either use the GUI to change the colormap using the drop down box on the left, or when you’re adding the image, you can specify the colormap parameter.

And if you’re adding each channel separately for example with the code above, then you can specify a different colormap for each channel.

So you could try something like this, where you can change the colormaps to whatever you’d like

import napari
from aicsimageio import AICSImage

img = AICSImage(filename)
channel_names = img.get_channel_names()

colormaps = ['magenta', 'cyan', 'red', 'yellow']

with napari.gui_qt():
    viewer = napari.Viewer()
    for c, c_name in enumerate(channel_names):
        viewer.add_image(img.get_image_data("ZYX", C=c, S=0, T=0), name=c_name, 
                        colormap=colormaps[c], blending='additive')
1 Like

Thank you.

Excuse me for the naive question. These stains have been used in the study to color the channels

Alexa Fluor 488 = Ch2 M-T1 #green-fluorescent dye
Alexa Fluor 405 = Ch1-T2 # blue-fluorescent dye
Cy3 = Ch3-T2 # orange-fluorescent dye

So is it possible to get the colormap from the dataset itself?

Unfortunately I’m still quite new to this stuff as well, so I’m honestly not too sure. That being said, this is from the documentation for add_image:

colormap : str, vispy.Color.Colormap, tuple, dict, list

Colormaps to use for luminance images. If a string must be the name
of a supported colormap from vispy or matplotlib. If a tuple the
first value must be a string to assign as a name to a colormap and
the second item must be a Colormap. If a dict the key must be a
string to assign as a name to a colormap and the value must be a
Colormap. If a list then must be same length as the axis that is
being expanded as channels, and each colormap is applied to each
new image layer.

So to answer your question, I think if you could provide some sort of mapping from the dye names to a colormap from vispy or matplotlib, then you could use that to set the colors of each channel. Alternatively, if no existing colormaps are sufficient, I think it’s also possible to create your own colormaps, in which case you could use that too.

Hopefully that helps, but as I said, I’m also quite new to this stuff so there might be a better way of doing it.

2 Likes

for the sake of completeness, also just want to point out that there is a channel_axis argument to viewer.add_image that will split your channels for you. And colormap will accept an array… so this becomes something like (assuming axis “0” has the color information):

viewer = napari.Viewer()
viewer.add_image(<full_array>, channel_axis=0, name=channel_names, colormap=colormaps)
3 Likes