我需要具有一个类似于此处的函数: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]))
Run Code Online (Sandbox Code Playgroud)
尝试运行此代码会导致以下错误:TypeError:**或pow()不支持的操作数类型:'NoneType'和'int'。就是这样吗?