Image.shape gives number of channels at the wrong position

Hello,

I am writing a script in python to perform a segmentation. I noticed, though, that I cannot use some packages because when I extract the shape of my images using img.shape, the number of channels is not at the end as expected but it is in second position.

As an example: I have an image composed of 250 pixels in xy, 50 slices and 2 channels.

from tifffile import imread

img = imread("image.tif")
print(img.shape)

I would expect to get as an outcome (50, 255, 255, 2).
Instead, I get (50, 2, 255, 255)

Does somebody know why the channel value is not returned as the last value?

I need to correct this because I use a python package whose functions may extract the last value as the number of channels and use this info later for computations. Does somebody know how I can fix this? :slight_smile:

Thank you!
Cheers,
Lucrezia

1 Like

Tifffile returns the dimensions/axes in the order they are stored in the file. In this case the channels were either saved as separate TIFF pages/IFDs or as separate planes within a page. Commonly only RGB(A) samples are stored contiguously (in the last axis) but it depends on the application that wrote the file. You can reorder the axes using numpy.moveaxis(img, 1, -1).

2 Likes