1

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 .

Jerika
  • 13
  • 3
  • Welcome to Stack Overflow. Please consider [taking the tour](https://stackoverflow.com/tour), and have a look at [how to ask](https://stackoverflow.com/help/how-to-ask) (good) questions around here. Please show any relevant code, and provide an actual input. Does the error also occur, when you save 30 slices from your original TIFF to some new TIFF? – HansHirse Mar 29 '21 at 10:38
  • it's just a normal loading " etval, mats = cv.imreadmulti(path) " my issue is that big files do not load, whereas if I test with small piece pf my original file with only 20 slices the file did load . I dont understand this weird behaviour once i proceed with my original tif file with 4000 slice. – Jerika Mar 29 '21 at 11:28
  • Maybe there's some fallback mechanism like: If you have insufficient memory to open all slices at once, just provide the first slice. You could try to open files with 100, 200, ... slices, and check if you find a memory or slice threshold or similar. – HansHirse Mar 29 '21 at 11:51
  • ImageJ only writes one IFD/page in case the TIFF file is larger than 4 GB. You need an ImageJ TIFF aware library such as [tifffile](https://pypi.org/project/tifffile/) to read the image data. – cgohlke Mar 29 '21 at 13:59

1 Answers1

0

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)
winsid
  • 48
  • 3