我需要一个类似于此处找到的函数:http://effbot.org/zone/pil-comparing-images.htm ,它可以计算两个图像之间的均方根差异。代码如下:
尝试运行此代码会导致以下错误:TypeError:不支持的操作数类型 ** 或 pow():'NoneType' 和 'int'。这是什么问题?
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:不支持的操作数类型 ** 或 pow():'NoneType' 和 'int'。这是什么问题?