cgohlke / tifffile

Read and write TIFF files
https://pypi.org/project/tifffile
BSD 3-Clause "New" or "Revised" License
544 stars 154 forks source link

Different axis ordering reading .tif files #87

Closed adrigrillo closed 3 years ago

adrigrillo commented 3 years ago

Hello,

I am writing this issue because I was playing with the SpaceNet 6 dataset and I have found a strange behavior when loading the files. In this dataset we can find several types of images, saved as geotiff, with a varying number of channels. For example, the RGB images have 3 channels whereas the SAR or RGBNIR ones have 4 channels.

What I found is that the behavior of the library changes depending on the channels when reading the file and creating the NumPy array. Concretely, the shape of the array is the following:

I do not understand why the order of the channels is different. I have tried using the scikit-image library, and it works as intended.

I attach in the following zip an RGB and a SAR image which can be used to reproduce the problem: example-images.zip

cgohlke commented 3 years ago

Tifffile returns the data in the order they are stored in the file (with the exception of some JPEG compressed files). The TIFF PlanarConfiguration tag describes two ways the components of a pixel (the Samples) can be stored. Your SAR image stores the samples contiguous (PlanarConfiguration=1). Your RGB image stores the samples in separate planes (PlanarConfiguration=2), which is not common for RGB images.