python图像领域平均_在python中平均多个图像

我试着用这个代码平均300张.tif图像:import os, numpy, PIL

from PIL import Image

# Access all PNG files in directory

allfiles=os.listdir(os.getcwd())

imlist=[filename for filename in allfiles if filename[-4:] in[".tif",".TIF"]]

# Assuming all images are the same size, get dimensions of first image

w,h = Image.open(imlist[0]).size

N = len(imlist)

# Create a numpy array of floats to store the average (assume RGB images)

arr = numpy.zeros((h,w,3),numpy.float)

# Build up average pixel intensities, casting each image as an array of floats

for im in imlist:

imarr = numpy.array(Image.open(im),dtype=numpy.float)

arr = arr+imarr/N

# Round values in array and cast as 16-bit integer

arr = numpy.array(numpy.round(arr),dtype=numpy.uint16)

# Generate, save and preview final image

out = Image.fromarray(arr,mode="RGB")

out.save("Average.tif")

它给了我一个这样的打字错误:

^{pr2}$

我知道它不喜欢在numpy数组中放入TIF图像(它也不适用于PNG图像)。我该怎么办?将每个图像分割成R、G和B数组进行平均,然后合并所有内容,这似乎太耗费内存了。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值