View multiple image stacks with same image settings

Hello - I have an image viewing task that I’d love help finding a solution for. I often collect data in a way such that I will have a collection of multi-channel z-stacks that I’d like to be able to view as a batch, with the same image settings applied across all images in the batch. (Similar to how the Zen software allows you to scroll through “scenes”, adjust contrast settings for each channel, apply those setting across all scenes, scroll through z and turn individual channels on and off.)

Does anyone know of a way to do this in one of the open source viewers (ie. Fiji or napari)? I can open batches of images in napari, but in my initial attempt, it uses the same color for all channels and I am not able to see an overlay of all of my channels.

Any advice would be really appreciated! Thank you!

Hello @melissah ! My understanding of your question is that you’d like to view collection of multichannel z stacks with different display settings (e.g., colormap, clims) applied to each channel. If I’ve understood correctly, I think I’ve I’ve made an example script below that will cover your use case.

We can use the channel_axis argument to the napari.view_image() (or viewer.add_image() if you already have a viewer constructed) method to specify which axis in our image corresponds to color channel. napari will then split our image into one layer per color channel so that you can set the display parameters for each color channel. You can then use the sliders to scroll through your other dimensions (e.g., time and z).

To be a bit more concrete, if we have a collection of 128 pixel x 128 pixel x 128 pixel volumes with 2 time points and 3 color channels, we can load those into python as an array with shape (2, 3, 128, 128, 128). Note that the color channel is axis 1. If we pass the keyword argument channel_axis=1 to napari.view_image(), napari will add 3 different Image layers overlaid (one for each color channel) and each of those Image layers would have an image with shape (2, 128, 128, 128). Since each color channel is in its own layer, you can set the display properties for each layer and those will be applied to all images in the color channel.

Does this help? Please let us know if you have any questions or comments!

import numpy as np
from skimage import data
import napari

# create "time point"
# (z stack with 3 color channels, shape 3x128x128x128)
blobs_t1 = np.stack(
        [
            data.binary_blobs(
                length=128, blob_size_fraction=0.05, n_dim=3, volume_fraction=f
            )
            for f in [0.05, 0.1, 0.15]
        ],
        axis=0,
)

# create second "time point"
# (z stack with 3 color channels, shape 3x128x128x128)
blobs_t2 = np.stack(
    [
        data.binary_blobs(
            length=128, blob_size_fraction=0.05, n_dim=3, volume_fraction=f
        )
        for f in [0.20, 0.25, 0.30]
    ],
    axis=0,
)

# combine time points
# 2 x 3 x 128 x 128 x 128 stack
blobs = np.stack([blobs_t1, blobs_t2])
print(blobs.shape)

with napari.gui_qt():
    # view stack with napari. note we specify the color channel is 
    # dimension 1 in the stack
    viewer = napari.view_image(blobs.astype(float), channel_axis=1)

When you use the channel_axis keyword argument, you can also pass the other parameters as a list to specify the value for each color channel Image layer. For example if our color channels are ordered DAPI, GFP, and RFP for channel indices 0, 1, and 2 respectively, we could set the names of the resulting layers as below

viewer = napari.view_image(image, channel_axis=1, name=['dapi', 'gfp', 'rfp'])
1 Like