Skip to content Skip to sidebar Skip to footer

Compare 2 Images And Find % Difference

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 imag

Solution 1:

Use compare which is part of ImageMagick. Like this:

compare -metric AE image1.png image2.png null:

The AE gives the absolute error, in terms of a count of the number of pixels difference. You can also use MAE (mean absolute error), or PAE (peak absolute error) or RMSE (root mean square error). You can also add a fuzz factor to allow slight differences in pixel values like this:

compare -fuzz 10% -metric AE image1.png image2.png null:

If you want the answer in a shell variable, say ndiff, you can do this:

ndiff=`compare -fuzz 10% -metric AE image1.png image2.png null: `
echo$ndiff

Post a Comment for "Compare 2 Images And Find % Difference"