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
kidman
Posts: 1
Joined: 2013-08-19T03:20:06-07:00
Authentication code: 6789

compare images with tolerance

Post by kidman »

Hi,

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
Image:
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?

Thanks.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compare images with tolerance

Post by Bonzo »

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
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: compare images with tolerance

Post by GreenKoopa »

Welcome. Also see
http://imagemagick.org/script/compare.php

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
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compare images with tolerance

Post by fmw42 »

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

http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
http://www.imagemagick.org/Usage/compare/#statistics
http://www.imagemagick.org/Usage/compose/#difference
Post Reply