I want to compare two images and know the % difference between them. I am using raspbian on raspberry pi and python language. I have found PIL and magickimage, but with magick image I can't find a function for this and with PIL I have strange results.
For Pil i use this code :
h1 = image1.histogram()
h2 = image2.histogram()
rms = math.sqrt(reduce(operator.add,map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
When i take two pics ( no difference ) with 0.5 seconds of intervall i have this results : rms = 4743.766.... If i move during between the two pics i have rms : 4699.288..... So it's does not make the difference between the two " sames " images and when i move :/
Use
compare
which is part of ImageMagick. Like this:The
AE
gives the absolute error, in terms of a count of the number of pixels difference. You can also useMAE
(mean absolute error), orPAE
(peak absolute error) orRMSE
(root mean square error). You can also add afuzz
factor to allow slight differences in pixel values like this:If you want the answer in a shell variable, say
ndiff
, you can do this: