compare images with tolerance

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Posts: 1
Joined: 2013-08-19T03:20:06-07:00
Authentication code: 6789

compare images with tolerance

Post by kidman » 2013-08-19T03:31:11-07:00


I want to compare images but with a user specified tolerance (ex. 20% diff is accepted). So what I have in mind is:

compare -verbose metric AE REF_IMAGE OUTPUT_IMAGE DIFF_IMAGE
The output looks like this:
OUTPUT_IMAGE PNG 598x484 598x484+0+0 8-bit DirectClass 25.5kb
REF_IMAGE PNG 598x484 598x484+0+0 8-bit DirectClass 25.5kb
Channel distortion: AE
red: 600
green: 600
blue: 600
all: 600

So the total image size in pixels is 598*484 and the number of diff pixels is 600 (extracted from "all"). And then dividing the diff by the total number pixels multiplied by 100 gives me the percentage of different region of the image. Is this a correct? Does "compare" offer this or better method?


Posts: 2699
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compare images with tolerance

Post by Bonzo » 2013-08-19T04:31:58-07:00

Have you checked the Usage site?

I wonder if you can use a -fuzz 20% and get an output if the image is over under the 20% difference?

User avatar
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: compare images with tolerance

Post by GreenKoopa » 2013-08-19T07:33:21-07:00

Welcome. Also see

Is AE the metric you want? Are only regions of your image changing? Is the image format lossless? Is a slightly brightened image 100% different?
AE = absolute error count, number of different pixels (-fuzz effected)

Or do you have your method working, and you only need pointers on formatting the output?

User avatar
Posts: 19899
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: compare images with tolerance

Post by fmw42 » 2013-08-19T10:11:51-07:00

Do your compare (I recommend using -metric rmse, but that is my preference) and then threshold the output to give you your 20% tolerance. You could also use -compose difference and the threshold the output. see

Post Reply

Who is online

Users browsing this forum: MSNbot Media and 11 guests