在PIL

时间:2016-09-10 06:27:15

标签: python image python-imaging-library tiff

我正在运行一个应该采用多帧tiff文件(黑白动画)的程序,扫描所有帧并确定它们的平均像素值,有效地允许我绘制Z轴轮廓。程序适用于单帧tiff,但每次我尝试使用动画时都会遇到类型错误。

im = Image.open('example_recording5.tif')
width,height = im.size
image_lookup = 0
n = 1
while True:
     try:
        im.seek(n)
        n = n+1
    except EOFError:
        print "End of sequence",  n
        break; 
#this sets a length argument (n) and allows to determine no of frames

class ImageSeq:
    def __init__(self, im):
        self.im = im
    def __getitem__(self, ix):
        try:
            if ix:
                self.im.seek(ix)
            return self.im
        except EOFError:
            raise IndexError 
result = []
c= 0 #(number of process repeptitions)

for index, frame in enumerate(ImageSeq(im)):
     total=0
     totalnew=0

    for i in range(0,width):
        for j in range(0,height):
            total = float (im.getpixel((i,j))[0])
            totalnew = totalnew + total
            mean_pixel_value = totalnew / (width * height)
    c = c+1    
    print c, mean_pixel_value

显示的错误如下,据我所知,它是由ImageSeq中的帧索引引起的;我该怎么做才能防止它呢? ''     total = float(im.getpixel((i,j))[0]) TypeError:' int'对象没有属性' getitem '''

0 个答案:

没有答案