Add algorithms/distance/rmsdiff.py
This commit is contained in:
parent
cf22ff2694
commit
72e37a252a
14
algorithms/distance/rmsdiff.py
Normal file
14
algorithms/distance/rmsdiff.py
Normal file
@ -0,0 +1,14 @@
|
||||
from PIL import ImageChops
|
||||
import math
|
||||
import operator
|
||||
import functools
|
||||
|
||||
def rmsdiff(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]))
|
Loading…
x
Reference in New Issue
Block a user