1

I've a huge TIF file of shape (39906, 30365, 4). I want to use it on PyQt5, however when I use PIL to open the image it gives the error "PIL.UnidentifiedImageError: cannot identify image file". I've searched and it seems that PIL can open TIF/TIFF files, but it has to be 8bit and my image is 8bit.

What could I do fix it? Is the file to large to be open by PIL? Is there another option to open a huge TIF to be used with PyQt5?

It's not necessary to open the whole image. Actually, if I could open a 25% scaled version of the original would be better.

Pillow version = 7.2.0

FY Gamer
  • 197
  • 1
  • 1
  • 9
  • Try opening it with QImage – alec Aug 12 '20 at 05:27
  • Is that 4.8G? Maybe you could try scikit-image to open the file? There is a difference between TIF files < 4G and files larger. (Actually I don't remember the cutoff). Possibly the easiest solution would be to make a scaled copy of the file? – matt Aug 12 '20 at 05:27
  • @alec I tried. But it says that the QImage is null image. If I use QPixmap, the same happens. – FY Gamer Aug 12 '20 at 06:03
  • @matt it's 1.37 GB, but I'll try scikit-image. How could I scale copy the tif file? – FY Gamer Aug 12 '20 at 06:04
  • You could resize it in Terminal before you start with **ImageMagick** using `magick BIGBOY.TIF -resize 25% result.tif` - replace `magick` with `convert` if using v6. – Mark Setchell Aug 12 '20 at 07:56
  • 40k x 30k * 4 takes 4.8GB in memory. – Mark Setchell Aug 12 '20 at 08:03
  • @MarkSetchell You're right. It should be 4.8GB. This is shown when I use "magick identify BIGBOY.tif": "BIGBOY.tif TIFF64 39906x30365 39906x30365+0+0 8-bit sRGB 1.37325GiB 0.000u 0:00.052". I've tried the magick resize, but I got an error about it couldn't extend the cache. I'll give it another shot. – FY Gamer Aug 12 '20 at 13:47
  • Probably a duplicate of https://stackoverflow.com/questions/60860654/cannot-open-tif-file-due-to-cannot-identify-image-file-error – cgohlke Aug 12 '20 at 21:49

1 Answers1

1

If you are having issues handling very large images, consider using libvips, either in your Python code or in the Terminal. It is very fast and frugal with memory.

Here's an example for Terminal:

vipsthumbnail BIGBOY.TIF --size 10000x -o small.tif     # reduce width to 10000px

And see usingVIPSandShrink() here.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432