Napari issue opening float32 image

I have an issue opening a float32 image in napari.

When I try to load the image:

import napari

image ="deformation_field_0.tiff")

with napari.gui_qt():
    viewer = napari.Viewer()
    im_layer = viewer.add_image(image)

The image opens, and it’s the correct shape, but every pixel value (in the napari bar) is [1].

The image loads fine in FIJI, and loads fine with napari if I convert to 16 bit first. Ideally I’d be able to drag and drop into napari though.

Is there likely something funky with the image? Or does napari have an issue with 32 bit images?


first suspicion is on the image (edit: or perhaps some assumption we’re making in napari that the image does not meet?). Shouldn’t be any problem loading 32 bit data into napari. Can you provide a link to the image?

Hi @talley, the image is here.

Thanks for taking a look!

yeah, it’s a little of both: the image has a slightly funny shape, with a singleton dimension at the end:

In [17]: img = tifffile.imread('deformation_field_0.tiff')

In [18]: img.shape                                                           
Out[18]: (539, 310, 433, 1)

napari tries to guess whether an image is rgb based on the image shape, and if ndim > 2 and last_dim < 5, then it thinks it’s RGB. So for your image:

viewer = napari.Viewer()
layer = viewer.add_image(img)
layer.rgb  # True

If you force it not to be RGB with viewer.add_image(img, rgb=False), then you have a very narrow 1 pixel image (it assumes last axis is X). So the best bet is probably to squeeze the data before adding (or fix how you’re saving the image if that’s in your control):

1 Like

Thanks @talley, I didn’t notice the singleton dimension. Image now saved as 3, rather than 4D.

Thanks again for your help!

1 Like

Should we only do that for last dim=3 or last dim=4 rather than <5?

Yeah I was thinking that too. It still would have given a strange image, but it would have been immediately obvious

1 Like