Page 1 of 1

composite image woes with newer ImageMagick version

Posted: 2011-11-17T12:24:19-07:00
by adavisirl
I have two same-size png files, A.png and B.png.
Each has a white background, a black grid pattern, and some black dots.
The black dots are in different places in each image.
I want to overlay A on B, so that the result shows the dots in both A and B,
along with the grid pattern.

On a Linux box with ImageMagick 6.5.1-2 2010-01-06 Q16 OpenMP,
I do this successfully with
convert -composite -transparent white A.png B.png C.png

C.png is the result I want.
I have posted the plots online at: http://www.srl.caltech.edu/NuSTAR_Public/ad/

However, on another Linux box with ImageMagick 6.6.5-10 2011-02-08 Q16,
the result using the same command is an image with a completely black background,
and the grid-pattern has turned blue.
See C_bad.png on the website.

Can someone help me get the result I want, using ImageMagick 6.6.5-10 2011-02-08 Q16 ?
I've tried many permutations of arguments to the convert and composite commands, with no luck...
Thanks,
Andrew

Re: composite image woes with newer ImageMagick version

Posted: 2011-11-17T13:08:05-07:00
by dirk1976
Try the following command
convert -composite -transparent white A.png B.png -flatten +matte C.png

Re: composite image woes with newer ImageMagick version

Posted: 2011-11-17T13:16:26-07:00
by adavisirl
Thanks dirk1976, that works!
And it works on the older ImageMagick version also, another plus.

Cheers

Re: composite image woes with newer ImageMagick version

Posted: 2011-11-17T14:58:13-07:00
by fmw42
PNG has undergone quite a few changes over many releases and may have had some bugs along the way.

However, your syntax is not proper IM 6 syntax, though may still work. The images should be read first. I assume you are trying to composite the two images together and then make the result have transparency where it was white. If that is not the case, then please clarify what you are trying to do.

convert A.png B.png -composite -transparent white C.png

On the other hand if you want to make the two images have white become transparent before compositing them, then

convert A.png B.png -transparent white -composite C.png

see
http://www.imagemagick.org/Usage/basics/#why
http://www.imagemagick.org/Usage/layers/

Re: composite image woes with newer ImageMagick version

Posted: 2011-11-17T18:38:00-07:00
by anthony
dirk1976 wrote:Try the following command

Code: Select all

convert -composite -transparent white A.png B.png -flatten +matte C.pn
g
That command is completely non-sensical. the options are operations that get applied in the order given, and you are trying to compose images BEFORE they are read, invoking legacy option handling. You also do two composition methods for just two input images, and replace pure white in the first image with transparency, forgetting that images may be grayscale, and not simply pure black and white.

I strongly suggest you read IM examples Basics!
http://www.imagemagick.org/Usage/basics/

UPDATE: added to the above... IMv6 syntax...
http://www.imagemagick.org/Usage/basics/#syntax
This means the IMv6 syntax can now be simplified as being...

Code: Select all

    command { [-setting]... "image"|-operation }...  "output_image"
With the part in {...} being repeated with as many 'reads' or 'operations' you want or need, to process your images in the exact order required.


As the background of the images is white, and you want to preserve black, why not multiply the images. Anything black in either image becomes black in the result.

Code: Select all

  convert A.png B.png -compose multiply -composite C.png