Compare Images

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Compare Images

Post by guggy »

1. encoding:

Code: Select all

compare -channel Gray -dissimilarity-threshold 2.0 -metric phash $image1 $image2 x:
for this pair:

https://goo.gl/KaOhGJ
https://goo.gl/b4hvlZ

And get this response : 1.8198 (after trim)

Then I run this pair:

https://goo.gl/tscR66
https://goo.gl/vByunQ

response : 1.95927 (after trim)

obliviously one pair is the same and one not,

why I'm not seen it in the response? did i need to do something different?

There is any way maybe to get the phash not by compare command?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compare Images

Post by fmw42 »

I am not sure I understand your question. PHASH is not recommended for grayscale images. It is primarily for natural (photographic) color images. For grayscale images it uses 1/6 as many moments to compare.

What do you mean by "after trim"?

What do you mean by "why I'm not seen it in the response"? Do you mean why are the values so similar when one pair is different? If so, that is because PHASH is not recommended for grayscale images.

PHASH does not take into account transparency. It is also not recommended for graphic images with lots of similar color background.

I would recommend using another metric if the two images are the same size.

Code: Select all

compare -metric XXX image1 image2 null:
will show only the metric value. I usually use -metric rmse.

See http://www.imagemagick.org/Usage/compare/#statistics for the various metrics.

Please always provide your IM version and platform/OS, since syntax may vary.
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Re: Compare Images

Post by guggy »

O.K thanks,

I'll be more clear,

What I'm trying to do is to test 10,000 images and check for duplicates, the Images are not in the same size.

I tried the 'rmse' command but this one also gave me allot of differences between two images.

What is the recommended way to do that? Its also have to be in a reasonable run time.

version: ImageMagick 6.8.9-9
platform: Ubuntu 16.04
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare Images

Post by snibgo »

The first pair of images are similar (but are not duplicates, not even duplicates at different sizes).

The second pair are not similar.

One comparison method is to reduce the image to salient features (I use "-trim" for simplicity), and scale to exactly the same size. Windows CMD syntax.

Code: Select all

convert ph1.png ph2.png -trim +repage -resize "256x256^!" -metric RMSE -format %[distortion] -compare info:
0.162264

convert ph3.png ph4.png -trim +repage -resize "256x256^!" -metric RMSE -format %[distortion] -compare info:
0.4046
This gives reasonable results.
snibgo's IM pages: im.snibgo.com
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Re: Compare Images

Post by guggy »

Thanks allot!

This is really helpful,
I just have a small question, why if I ran this command with "x:" at the end instead of "info:" ,

I get a result display that cover almost all the image in red, if the response number say they almost equal?
Last edited by guggy on 2017-03-12T01:38:02-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare Images

Post by snibgo »

The "red" image shows pixels that are different, however much they are different. Personally, I often use something like this:

Code: Select all

convert ph1.png ph2.png -trim +repage -resize "256x256^!" -alpha off compose Difference -composite x.png
This is black where there is no difference, or shades of gray up to white where there is a maximum possible difference. Where images are very similar, it needs "-auto-level" before the output.
snibgo's IM pages: im.snibgo.com
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Re: Compare Images

Post by guggy »

O.k Thanks ,

I tested more than 1000 images and its works really good.
I have 3 pairs that are not the same but they got score of 1.5 like this pair :

https://goo.gl/5EQezx
https://goo.gl/zJxphY

Do you know maybe why IM not found more differences between them?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare Images

Post by snibgo »

Come on, please give us at least half a chance. What command on those images gave you "1.5"?
snibgo's IM pages: im.snibgo.com
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Re: Compare Images

Post by guggy »

Sorry my bad,

this is the command :

"convert ${image1} ${image2} +repage -resize "256x256^!" -metric RMSE -format %[distortion] -compare info:"

Its what we talks about before.

the result I get is : 0.1826

version: ImageMagick 6.8.9-9
platform: Ubuntu 16.04
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare Images

Post by snibgo »

I suggest you "-trim" before the "+repage".
snibgo's IM pages: im.snibgo.com
guggy
Posts: 6
Joined: 2017-03-08T07:53:58-07:00
Authentication code: 1151

Re: Compare Images

Post by guggy »

That true, thanks again!
Post Reply