Page 1 of 1

Compare Images

Posted: 2017-03-08T10:31:20-07:00
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?

Re: Compare Images

Posted: 2017-03-08T11:30:02-07:00
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.

Re: Compare Images

Posted: 2017-03-09T02:00:46-07:00
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

Re: Compare Images

Posted: 2017-03-09T03:26:50-07:00
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.

Re: Compare Images

Posted: 2017-03-09T07:00:26-07:00
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?

Re: Compare Images

Posted: 2017-03-09T07:45:58-07:00
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.

Re: Compare Images

Posted: 2017-03-14T01:23:36-07:00
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?

Re: Compare Images

Posted: 2017-03-14T03:13:43-07:00
by snibgo
Come on, please give us at least half a chance. What command on those images gave you "1.5"?

Re: Compare Images

Posted: 2017-03-14T05:38:19-07:00
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

Re: Compare Images

Posted: 2017-03-14T05:49:11-07:00
by snibgo
I suggest you "-trim" before the "+repage".

Re: Compare Images

Posted: 2017-03-14T06:52:37-07:00
by guggy
That true, thanks again!