Imagemagick compare: "images too dissimilar"

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Imagemagick compare: "images too dissimilar"

Post by peter_b »

[PROBLEM]
I tried to compare two images using ImageMagick's "compare", but always received the following error:
compare: images too dissimilar `color_squares/b-b.png' @ error/compare.c/CompareImageCommand/926.
The code has worked in the past, but it seems that the ImageMagick version got updated in the meantime to "ImageMagick 6.6.0-4 2012-05-03 Q16":

Code: Select all

compare -metric AE -fuzz 40% $IMAGE_1 $IMAGE_2 null: 2>&1 > /dev/null
My version redirects stdout and stderr to /dev/null. The returned value of this call is just the number of pixels that differ.
This is necessary to use it in a BASH script.


[SOLUTION]
Older versions of imagemagick didn't check how different the image was, before running the actual pixel comparison.
There's a new parameter called "dissimilarity-threshold".
If the images you'd like to compare could be very very different, you might want to set it to 1:

Code: Select all

compare -dissimilarity-threshold 1 -metric AE -fuzz 40% $IMAGE_1 $IMAGE_2 null: 2>&1 > /dev/null
Thanks to a forum-post by user "fmw42" on imagemagick.org.
Post Reply