Skip to content Skip to sidebar Skip to footer

Plt.imread(img) Raises Pil.unidentifiedimageerror

So when I try to use imread on a TIFF-file, it raises this error. The TIFF-file in question is a TIFF I created and modified in another script. I initially created it like this: te

Solution 1:

Your image is a 64-bit floating point TIFF. You can see that with:

tiffinfo v3l1_24-34.tiff

Or with ImageMagick:

magick identify -verbose v3l1_24-34.tiff

PIL doesn't like such things, so you either need to either create it as 32-bit:

temp = np.full(..., dtype=np.float32)

or, if you need 64-bit, maybe read it with tifffile:

import tifffile
...
im = tiffffile.imread('v3l1_24-34.tiff')

If you have some pre-existing BigTIFF files you want to make into 32-bit classic TIFF files, you can try the following commands:

# Use an ImageMagick version with Q16 or higher and HDRI when you run "identify -version"
magick input.tif -define quantum:format=floating-point -depth 32output.tif

# Or use "libvips"in the Terminal
vips im_vips2tiff input.tif output.tif

To check if a file is a BigTIFF or not, use exiftool and look for BTF like this:

exiftoolbigtiff.tifExifTool Version Number         :11.11File Name                       :bigtiff.tifDirectory                       :.File Size                       :1024 kBFile Modification Date/Time     :2020:03:1313:56:05+00:00File Access Date/Time           :2020:03:1313:56:19+00:00File Inode Change Date/Time     :2020:03:1313:56:11+00:00File Permissions                :rw-r--r--File Type                       :BTF<---HERE......

Or use xxd like this and look for 3rd byte being 0x2b:

xxdbigtiff.tif|more00000000:4949 2b000800 0000 1000 1000 0000 0000  II+...................

whereas a ClassicTIFF shows up as 0x2a:

xxdclassic.tiff|more00000000:4949 2a000800 1000 0000 803f0000 803fII*........?...?

Post a Comment for "Plt.imread(img) Raises Pil.unidentifiedimageerror"