Page 1 of 1

Use ImageMagic to compare Images

Posted: 2014-06-30T06:24:24-07:00
by Levan
want to compare a source png file to a compressed file.

I am using imagemagick and this command:

Code: Select all

convert image1 image2 -compose Difference -composite \
       -colorspace gray -format '%[fx:mean*100]' info:
But what I get is a very odd number. I am looking from a number from 0-100%.

When I compared two totally different images I still get a 8.37885.

So good people of Ask Ubuntu, can you provide me with a command that will measure the difference between files properly and give me a number from 0-100?

For example

Image

Image

Get 42.0838

Code: Select all

convert image1 image2 -compose Difference -composite  -format '%[fx:mean*100]' info:
With this command I get: 57.2969

So it there something wrong with the command I use ?? If yes can you recommend alternative??

Thank you for your help. Thank You

Re: Use ImageMagic to compare Images

Posted: 2014-06-30T10:13:10-07:00
by fmw42
On these two image with IM 6.8.9.4 Q16 Mac OSX I get

Code: Select all

convert 1.png 2.png -compose Difference -composite -colorspace gray -format '%[fx:mean*100]' info:
48.3854

So that is 48.3854%, which is a reasonable value, since fx:mean returns values between 0 and 1. However, you are weighting the r,g,b values unequally by using -colorspace gray.

So you might use

Code: Select all

convert 1.png 2.png -compose Difference -composite -grayscale average -format '%[fx:mean*100]' info:
57.2969

What version of IM are you using?

Another way to compare these images is with compare

Code: Select all

compare -metric rmse 1.png 2.png null:
46321.8 (0.706825)

Take the second and multiply by 100, gives 70.6825% using the rmse metric

This is pretty much the same as doing

Code: Select all

convert 1.png 2.png -compose Difference -composite -grayscale rms -format '%[fx:mean*100]' info:
70.1065


see
http://www.imagemagick.org/Usage/compare/
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/script/comma ... #grayscale

Re: Use ImageMagic to compare Images

Posted: 2014-07-01T07:35:40-07:00
by Levan
fmw42

Thank you very much for your reply, and I apologize for taking so long to write you back.

I am using: ImageMagick 6.7.7-10 2014-03-06 Q16 version

The information you provided is very helpful so thank you for that.

Again thank you, you have been tremendous help

Re: Use ImageMagic to compare Images

Posted: 2014-07-01T09:15:00-07:00
by fmw42
IM 6.7.7.10 is ancient and too old for the function -grayscale. You should upgrade IM if possible. Your IM is over 100 versions old.

Re: Use ImageMagic to compare Images

Posted: 2014-07-01T15:47:08-07:00
by Levan
fmw42 wrote:IM 6.7.7.10 is ancient and too old for the function -grayscale. You should upgrade IM if possible. Your IM is over 100 versions old.
Thank you very much for the information, I will make sure to compile the latest version.