Python PIL For Loop可与多图像TIFF一起使用 [英] Python PIL For Loop to work with Multi-image TIFF
本文介绍了Python PIL For Loop可与多图像TIFF一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每个tiff文件中都有4张图像.我不希望提取并保存它们(如果可能),我只想使用一个for循环来查看它们中的每一个. (就像查看像素[0,0]一样),并根据所有4种颜色的不同,我会做相应的事情.
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.
使用PIL可以吗? 如果没有,我该怎么用.
Is this possible using PIL? If not what should I use.
推荐答案
您可以使用PIL图像的搜索"方法来访问tif的不同页面(或动画gif的帧).>
You can use the "seek" method of a PIL image to have access to the different pages of a tif (or frames of an animated gif).
from PIL import Image
img = Image.open('multipage.tif')
for i in range(4):
try:
img.seek(i)
print img.getpixel( (0, 0))
except EOFError:
# Not enough frames in img
break
这篇关于Python PIL For Loop可与多图像TIFF一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文