I’m trying to add all the .tiff files in a directory together using ImageChops, but I keep on getting the error ‘IOError: cannot identify image file’. I thought it was just a problem with trying to use a file path instead of an image object, but similar codes in other places don’t have this problem.
def imadd(): #subcommand
img1=Image.new('RGB',(2048, 2048))
img1.save("summation.tif")
for file in os.listdir(directoryname):
if fnmatch.fnmatch(file, '*.tif'):
im2 = Image.open("summation.tif", mode='r')
im3 = Image.open(os.path.join(directoryname, file))
finalimg = ImageChops.add(im2, im3, 1, 0)
finalimg.save("summation.tif")
By trail and error, all the parts work except:
im3 = Image.open(os.path.join(directoryname, file)).
I also tried using glob.glob(), but that still returns the same error.
While you can open and show 16 bit tiffs with PIL, ImageChops doesn’t work. matplotlib and scipy have many more tools available.
Also im3 = Image.open(os.path.join(directoryname, file)) needs to be Image.open(unicode(os.path.join(directoryname, file)))