ImageMagick Compare

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.
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

Hi fmw42,
I had just one more query.
Is it possible to merge this "difference.png" image either to the 1st or 2nd image so that the differences are highlighted within the image and not as a
separate one.Is "compose" or "blend" gonna work??
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

It is possible to use -compose ... -composite to do what you want. However, I have lost track of the topic as you opened a new one. Can you put links to your input images and the difference image and the command you used to generate it. Also link to the old topic so I can find it.
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

Hi,
Actually I didn't create a new topic.This just moved to the 2nd page :)
The post is here.
viewtopic.php?f=2&t=20626
The links for the images are
http://imgur.com/azunh
http://imgur.com/FeAYq

WE used the following command to get the difference image.
convert azunh.png -shave 20x20 -fuzz 10% -trim +repage -threshold 70% azunh_test.png
convert FeAYq.png -threshold 70% FeAYq_test.png
compare -metric rmse -subimage-search 1FeAYq_test.png azunh_test.png similarity_test.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

You really need to test this without you red marker. But try this

convert azunh.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( similarity_test-0.png -fuzz 25% -fill black +opaque red -fill white -opaque red -morphology open disk:1.5 \) \
-compose over -composite azunh_diff.png
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

Thanks for replying.
I tried running this command on the same pics.
But I am getting only a completely "black" image in this case.
I could not follow what you aredoing in this command by the "clone" and "fill blue" parameters and some of the other options you are using?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

What is your IM version and platform? That may be critical. Again can you provide the same pictures without the red marker showing. It would be a better test and allow for perhaps some tweaking to make it better.
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

Hi,
The IM version I am running is 6.7.4-6 .
I have again upload the clean images.
http://imgur.com/bgLdo,E65lI#1
http://imgur.com/bgLdo,E65lI#2

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

try this


convert bgLdo.png -shave 20x20 -fuzz 15% -trim +repage -threshold 70% bgLdo_test.png
convert E65lI.png -shave 20x20 -threshold 70% E65lI_test.png
compare -metric rmse -subimage-search E65lI_test.png bgLdo_test.png similarity_test.png

convert bgLdo.png -shave 20x20 \
\( -clone 0 -fill red -colorize 100 \) \
\( similarity_test-0.png -fuzz 25% -fill black +opaque red -fill white -opaque red \) \
-compose over -composite bgLdo_diff.png
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

thanks.this is working pretty fine.
can you explain a little what are you doing in the last command?
Can it be possible to darken the "difference" which is being shown in RED ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

1st line -- open and shave 20 pixels around the image (same as was done in the earlier processing)
2nd line -- clone the previous image and make it all red
3rd line -- convert the first similarity image so that red becomes white and the rest becomes black to use as a mask
4th line -- composite the red image with the original shaved image using the mask to make the red show only where there are differences
convert bgLdo.png -shave 20x20 \
\( -clone 0 -fill red -colorize 100 \) \
\( similarity_test-0.png -fuzz 25% -fill black +opaque red -fill white -opaque red \) \
-compose over -composite bgLdo_diff.png

The only way I know to make the highlight darker is to choose a different and darker shade of red or some other color besides "red" in line 2. See various colornames at http://www.imagemagick.org/script/color.php

Alternately you could decrease the brightness and contrast of the image.


Try


convert 1bgLdo.png -shave 20x20 -brightness-contrast 20,-50 \
\( -clone 0 -fill red -colorize 100 \) \
\( 1similarity_test-0.png -fuzz 25% -fill black +opaque red -fill white -opaque red \) \
-compose over -composite 1bgLdo_diff.png

Just vary the brightness-contrast values to get what you like, e.g. 0,-50 or 20,-50 or 50,-50 or whatever suits you.
gaurav_kl
Posts: 14
Joined: 2012-03-28T12:28:56-07:00
Authentication code: 8675308

Re: ImageMagick Compare

Post by gaurav_kl »

Hi,'
Thanks for all your help throughout.
I worked fine for my project.
I was doing some further work on my project regarding this and wanted to ask a few things.
So is ImageMagick doing the "Image registration" when it does "sub-image" search.
I need to get the registered images for some task.
I know you had told about using "distortion" for this but I wanted to ask if IM is doing some feature-matching for
the "subimage-search" or does it register the images using distortion only?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

gaurav_kl wrote:Hi,'
Thanks for all your help throughout.
I worked fine for my project.
I was doing some further work on my project regarding this and wanted to ask a few things.
So is ImageMagick doing the "Image registration" when it does "sub-image" search.
I need to get the registered images for some task.
I know you had told about using "distortion" for this but I wanted to ask if IM is doing some feature-matching for
the "subimage-search" or does it register the images using distortion only?

It simply takes each subsection of the large image and does a statistical comparison (such rmse) with the smaller image to get a match score for each compare. Then it reports the subsection with the best match and that match value.

There is no registration in the sense of distorting one image to match the other. There are no features extracted from either image to match agains. It is strictly a pixel by pixel color distance measure and sum of the results
Isis
Posts: 1
Joined: 2012-08-23T03:11:49-07:00
Authentication code: 67789

Re: ImageMagick Compare

Post by Isis »

Hi fmw42:

Related to your answer:
In order to do any comparison of two images, they need to be the same size and scaled and rotated properly. Compare can handle two images of different size, but it will find the best match location of the smaller one with the larger one.

I have several questions.

I have a reference image and I compare to another one that is supposed to be equal, somethimes due to the PC the margins can be bigger. You said that it is possible to get the best match location but I get the following error:

compare.exe -metric AE C:\image1.bmp C:\image3.bmp C:\result.bmp
compare.exe: image widths or heights differ `C:\image1.bmp' @ error/compare.c/Co
mpareImageCommand/962.

I have tried with -subimage-search but then it is necessary that the big image contain a exactly copy of the small one otherwise I get an error.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick Compare

Post by fmw42 »

subimage-search should work fine unless the two images are very very different. Then you need to add -dissimilarity-threshold 100%. Note I generally use -metric rmse for different size images.

see my example at viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076

Note it now needs -subimage-search added in more current versions of IM

Otherwise, post links to your two images on the forum and I will try to test them.

Fred
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: ImageMagick Compare

Post by pipitas »

fmw42 wrote:You really need to test this without you red marker. But try this
convert azunh.png \
\( -clone 0 -fill blue -colorize 100 \) \
\( similarity_test-0.png -fuzz 25% -fill black +opaque red -fill white -opaque red -morphology open disk:1.5 \) \
-compose over -composite azunh_diff.png
Hmmm... I'm getting this result:
Image
If it wasn't for the colored marks in the two files, there wouldn't be any highlight of the delta...
Post Reply