python-3.xopencvtifffiji

Loading a large tif file but only first slice is loaded in openCV


I'm in a process to write a code in order to process my tiff files .

I manage to load tif files with 20 to 30 slices but when I proceed to work on my original files with 4000 slices only first slice is loaded . I don't get any type of error. I even proceeded to re-save those files using FIJI image J into tiff files in case the originals were corrupted but same results .

This is one of my original files : https://www.dropbox.com/s/wtkyj9qzxw4q1uf/CT_Part.tif?dl=0

    etval, mats = cv.imreadmulti(tif, flags=cv.IMREAD_GRAYSCALE)
    print(len(mats))

So this print output 1 instead of 4000 slice . Again if I test with small piece of my original file with only 20 slices I get indeed 20 .

Opencv version : 4.5.1 Python version : 3.8.3

Any explanation or suggestion would be greatly appreciated .


Solution

  • Use tifffile library, in case of your code you can replace it in the following way :

    import tifffile as tiffio
    mats = tiffio.imread(tif_path)