0
votes

I want make 2 different colors on the output image when using Imagemagick. I have an original image with "Hello World" in it. And a modified image with "Hello Warcraft" in the same area. The default compare command will give me a image and mark all the differences with red.

Now I want to use 2 different colors like "orld" marked as red, and "arcraft" marked as another color, maybe blue. Is ImageMagick able to do this?

If not, how to use ImageMagick to transfer a specified color to another one?

Below are the sample.

Image A

Image B

Then I use the compare like: compare imageA.png imageB.png imageC.png

then the Image C will be:

Image C

But now I just know there are some differences between Image A and Image B. so I want to make some color-code on the Image C, it could be like below Image D:

Image D

from this I can know which parts are the same, and Green means what the difference on Image A and Red means what's the difference on Image B.

1
I do not understand the question. Can you post some example images to a free hosting service and put the URLs here? Then explain a bit better what you want.fmw42
Sorry, I don't have free server. I will try to explain it like this: Image A show a car, Image B show a bike, if compare them, both car and bike will be marked as red color on image C. right? now I want to do some color-marked. the car is blue and bike is red. so I can get infomation from image C that how differences between A and B.LeonLee

1 Answers

2
votes

You can do this in ImageMagick 6 (Unix Syntax).

ImageA:

enter image description here

ImageB:

enter image description here

convert img1.png img2b.png \
-define compose:args="0,1,-1,0.5" \
-compose mathematics -composite -auto-level \
\( xc:red xc:blue +append \) -clut diff.png


enter image description here

This is a biased difference. Anything above 0.5 or mid gray (in normalized values) will be one color corresponding to one image and anything below 0.5 will be the other color corresponding to the other image.

See clut and compose mathematics

For ImageMagick 7, change convert to magick.

ADDITION:

Given your new input images. Here is how to do that:

imageA:

enter image description here

imageB:

enter image description here

convert imageA.png imageB.png -write mpr:img +delete -fill white -colorize 80% \
\( mpr:img -compose minus -composite -threshold 0 -background red -alpha shape \) \
\( mpr:img +swap -compose minus -composite -threshold 0 -background blue -alpha shape \) \
-background none -compose over -flatten result.png


enter image description here

Sorry, I used blue in stead of green. But you can change that if you want.