【发布时间】:2011-03-07 02:51:18
【问题描述】:
我需要一个像这里找到的函数:http://effbot.org/zone/pil-comparing-images.htm,它计算两个图像之间的均方根差。代码如下所示:
import ImageChops
import math, operator
def rmsdiff(im1, im2):
"Calculate the root-mean-square difference between two images"
h = ImageChops.difference(im1, im2).histogram()
# calculate rms
return math.sqrt(reduce(operator.add,
map(lambda h, i: h*(i**2), h, range(256))
) / (float(im1.size[0]) * im1.size[1]))
尝试运行此代码会导致以下错误:TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'。有什么问题吗?
【问题讨论】: