ich moechte zwei Bilder vergleichen und bin zuerst auf das PIL Modul und anschliessend auf diese Funktion gestossen:
Code: Alles auswählen
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]))
Wenn ich das entsprechend umsetze und das hier probiere:
Code: Alles auswählen
import ImageChops
import math, operator
import PIL.Image
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]))
im1 = PIL.Image.open(r"C:\Python25\bild1.jpg")
im2 = PIL.Image.open(r"C:\Python25\bild2.jpg")
rmsdiff(im1, im2)
Traceback (most recent call last):
File "C:\Python25\test.py", line 18, in <module>
rmsdiff(im1, im2)
File "C:\Python25\test.py", line 12, in rmsdiff
map(lambda h, i: h*(i**2), h, range(256))
File "C:\Python25\test.py", line 12, in <lambda>
map(lambda h, i: h*(i**2), h, range(256))
TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'
Kann mir jemand erklaeren, was ich falsch mache?
Gisi