18 lines
495 B
Python
18 lines
495 B
Python
from PIL import ImageChops
|
|
import math
|
|
import operator
|
|
import functools
|
|
import numpy as np
|
|
|
|
def rmsDiffPil(im1, im2):
|
|
"Calculate the root-mean-square difference between two images"
|
|
|
|
h = ImageChops.difference(im1, im2).histogram()
|
|
|
|
# calculate rms
|
|
return math.sqrt(functools.reduce(operator.add,
|
|
map(lambda h, i: h*(i**2), h, range(256))
|
|
) / (float(im1.size[0]) * im1.size[1]))
|
|
|
|
def rmsDiffNumpy(image0, image1):
|
|
return np.sqrt(np.mean(np.square(image0 - image1))) |