Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi channel image -- ERROR tuple index out of range #48

Open
manerotoni opened this issue Nov 13, 2023 · 2 comments
Open

Multi channel image -- ERROR tuple index out of range #48

manerotoni opened this issue Nov 13, 2023 · 2 comments

Comments

@manerotoni
Copy link

manerotoni commented Nov 13, 2023

Hello,
I was wondering how you are supposed to load a multi-channel image in the plugin.

Problem

  • If I load a multipage tif with two channels and python dimensions (C, Y, X), the plugin
    gives the error ERROR tuple index out of range
  • If I set the stitch threshold > 0 or 3D on the image is processed as Z-stack, which is wrong.

I conclude from this that the plugin always think that an image with more than 2-dimension is a Z-stack.

What I tried

  1. Napari expects dimensions (T, Z, C, Y, X) and I tried to add more dimensions. This did not help. In fact to display the image as multi-channel you need to split stack.

  2. I converted in Fiji the image to a png/RGB. The image gets dimension (Y,X, C) with 3 channels. Napari displays the image as multi-channel without having to split stack. Cellpose can process the image. This solution is not good as converting yet in another format is not convenient and is something you try to avoid in image processing due to loss of information. If you try to make your image RGB in napari/python it is quite of a mess. You have to add an additional channel , ....

Possible solutions
Specify the channels to use directly without going through the image layer. The plugin should understand different dimensions. In the cellpose GUI this works quite well.

@psobolewskiPhD
Copy link
Contributor

Yeah I can reproduce this. The channel to segment menu is not very intuitive so it makes it seem like it should work, but it doesn't. The issue likes here:

if image_layer.ndim == 4 and not image_layer.rgb:
chan = np.nonzero([a=='c' for a in viewer.dims.axis_labels])[0]
if len(chan) > 0:
chan = chan[0]
widget.channel_axis = chan
widget.n_channels = image.shape[chan]
elif image_layer.ndim==3 and not image_layer.rgb:
image = image[:,:,:,np.newaxis]

So if you have a multichannel 3D image (4 dims) then you can make it work by naming one of the axes c e.g. by double clicking the number next to the axis or by providing a tuple to axis_labels.
For example lets say I have CZYX, I would do:
viewer.dims.axis_labels = ('c', 1, 2, 3)
Then using channel to segment I can specify which channel to use and the axes labeled c will be used.
Alas, for CYX there is no similar check.
What would make more sense overall is if the channel_axis could be directly specified in the widget UI.
I'll take a look.

@manerotoni
Copy link
Author

Thanks,
are you saying that for a standard CXY image it is not possible to use the napari cellpose plugin except by converting it to a different order image? I have not tried to change the order of the numpy array in python. Do you know if this works (no conversion to RGB).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants