Comparing 2 Images

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
LemmingOnTheRun
Posts: 3
Joined: 2013-11-08T11:41:22-07:00
Authentication code: 6789

Comparing 2 Images

Post by LemmingOnTheRun »

I have 2 .png files that I want to compare. After using compare I get a working image as expected, but I want more data than this. Is there any way to get compare to spit out the actual values (how many red pixels became green, how many green pixels became yellow, etc)? If so is there any way to then DISPLAY these values in the resulting image?

Version: ImageMagick 6.8.7-0 2013-09-18 Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Comparing 2 Images

Post by fmw42 »

can you post links to your two images so we can try some things? you can post to some free service such as dropbox and then put links here.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Comparing 2 Images

Post by snibgo »

There are many possibilities, such as:

- Use "compose difference" (or minus) to see what pixels have changed.

- Use "-separate" to see the differences per red, green or blue channel.

- Create a mask to show just the changed pixels, or just the pixels where the green channel has changed, or just where the green channel has increased.
snibgo's IM pages: im.snibgo.com
LemmingOnTheRun
Posts: 3
Joined: 2013-11-08T11:41:22-07:00
Authentication code: 6789

Re: Comparing 2 Images

Post by LemmingOnTheRun »

Here's a link to some examples. Also these were converted from svg files, and any tips on getting rid of that black stuff (not in the original svg file) would be appreciated...

https://www.dropbox.com/sh/i07yphgrk625bre/i4FCGjcO5E
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Comparing 2 Images

Post by snibgo »

With current Inkscape (0.48) and recent IM (v6.8.7-0) I get no black bits, using convert with no options.

Code: Select all

convert example.svg e0.png
convert example_template.svg e1.png
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Comparing 2 Images

Post by fmw42 »

Here is one method. Remap the colors to the basic colors to fill in the anti-aliased colors. Then get the histogram. It shows the counts of each color

convert xc:white xc:black xc:"#41ff1a" xc:"#f50015" xc:"#fcff24" +append map.png


convert example.png +dither -remap map.png -depth 8 -format "%c" histogram:info:
3311: ( 0, 0, 0,255) #000000 black
5083: ( 65,255, 26,255) #41FF1A srgba(65,255,26,1) ----> green
1715: (245, 0, 21,255) #F50015 srgba(245,0,21,1) ----> red
4229: (252,255, 36,255) #FCFF24 srgba(252,255,36,1) ---->yellow
768350: (255,255,255,255) #FFFFFF white
LemmingOnTheRun
Posts: 3
Joined: 2013-11-08T11:41:22-07:00
Authentication code: 6789

Re: Comparing 2 Images

Post by LemmingOnTheRun »

That's a cool idea, but it doesn't preserve location within the image. (like, I need to know where in the image the colors changed). I'll take a look at it tho, definitely seems useful

EDIT: compose was exactly what I was looking for, thanks! I'll have to play with this and write a script that integrates the visual and histogram components, but this should work perfectly, thanks everyone!
Post Reply