Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL For Loop to work with Multi-image TIFF

Each tiff file has 4 images in it. I do not wish to extract and save them if possible, I would just like to use a for loop to look at each of them. (Like look at the pixel [0,0] )and depending on what color it is in all 4 I will do something accordingly.

Is this possible using PIL? If not what should I use.

like image 281
1478963 Avatar asked Sep 03 '13 22:09

1478963


People also ask

Can TIFF store multiple images?

Advantages of TIFF files. The file can work as a container for smaller-sized JPEGs, storing multiple images in one master raster graphic.


1 Answers

Rather than looping until an EOFError, one can iterate over the image pages using PIL.ImageSequence (which effectively is equivalent as seen on the source code).

from PIL import Image, ImageSequence

im = Image.open("multipage.tif")

for i, page in enumerate(ImageSequence.Iterator(im)):
    page.save("page%d.png" % i)
like image 139
Maxim Avatar answered Sep 29 '22 18:09

Maxim