0

My main aim is to produce 1D array out of each image in the 'dengue' folder. For which I used below code to read the file using both PIL and GLOB.

from PIL import Image import glob

image_list = []
for filename in glob.glob('./dengue/*.tiff'): 
    im=Image.open(filename)
    image_list.append(im)

OUTPUT IS -

UnidentifiedImageError: cannot identify image file './dengue/image_2016-09-18.tiff

How to resolve this? The same error showed up for numerous other images.

Or is there any other way I can read each of these tiff images to produce 1D array out of them? Thank you so much for your time.

Aaron
  • 10,133
  • 1
  • 24
  • 40
  • When I used just the glob all the images in the folder "dengue" did read. The code I used is below. ''' import glob2 dengue_files = glob2.glob('./dengue/*.tiff') dengue_files ``` –  Nov 15 '21 at 17:42
  • This can happen whenever PIL does not support the image format, or whenever there's corrupted data in one of the image files. use a `try: except:` block around `Image.open()` and print out the problematic files for further investigation (ie: figure out how they're different from images that work fine) – Aaron Nov 15 '21 at 17:51
  • [New-ish versions of Pillow fully support tiff](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#tiff), so I would lean towards non-standard or corrupted tiff files. – Aaron Nov 15 '21 at 17:54

1 Answers1

1

Use one of the following tools to see the difference between a TIFF file you can read and one you cannot:

exiftool UNHAPPY.TIF

or, with tiffinfo from libtiff:

tiffinfo UNHAPPY.TIF

or, with ImageMagick:

magick identify -verbose UNHAPPY.TIF

My guess would be you have an unsupported compression or pixel type.

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