小编pyt*_*der的帖子

使用Python和PIL的两个图像之间的均方根差

我需要具有一个类似于此处的函数: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'。就是这样吗?

python image-processing

5
推荐指数
2
解决办法
8503
查看次数

标签 统计

image-processing ×1

python ×1