Page 1 of 2

Composite with different transparencies

Posted: 2010-12-07T15:14:07-07:00
by weatherbadger
Hi

Been a while. Upgraded laptop with Opensuse 11.3 and ImageMagick 6.6.1-0 2010-07-29 and can't now make a good composite of two images:

http://www.weatherbadger.com/Charts/tes ... _rain4.png is the varying transparent base.
http://www.weatherbadger.com/Charts/test/USAsnow4.png has a transparent background and should just fit on top.

I used to use a very simple

Code: Select all

composite USAsnow4.png transp_rain4.png finalimg.png
in my scripts which worked fine! This now seems to screw up the transparency somewhere. I'm not quite sure why - it may be the images themselves are being made slightly differently).

Can anyone suggest a quick fix please?

Cheers
WB

Re: Composite with different transparencies

Posted: 2010-12-07T15:44:53-07:00
by GreenKoopa
weatherbadger wrote: Can anyone suggest a quick fix please?
convert USAsnow4.png transp_rain4.png -background white -flatten finalimg.png

Both images have transparency. What should the final image be where both inputs are transparent? I assumed white above.

Re: Composite with different transparencies

Posted: 2010-12-07T15:53:19-07:00
by weatherbadger
Sorry, I realise I wasn't clear, I want the background as transparent. ie the transp_rain4.png with the snow image on top.

-background doesn't have a transparent option¸so how can I ensure this transparency is copied across?

Re: Composite with different transparencies

Posted: 2010-12-07T15:58:06-07:00
by weatherbadger
Just to clarify further, the final result should look something like
http://www.weatherbadger.com/Charts/tes ... ecip39.png
where the snow (white to grey) is opaque and the rain (blue) is varying transparency. all on a transparent background...

Cheers
WB

Re: Composite with different transparencies

Posted: 2010-12-07T16:05:25-07:00
by GreenKoopa
What you are doing looks like it should work to me, but I'm not very experienced. The black seem strange. Even stranger, swapping the image order makes the black go away. I do notice that one image uses transparent black, the other transparent white. You can try setting -compose. I'll ponder it.

Re: Composite with different transparencies

Posted: 2010-12-07T16:33:20-07:00
by anthony
weatherbadger wrote:-background doesn't have a transparent option¸so how can I ensure this transparency is copied across?
Actually it does... use a background color of 'None' or "Transparent' :-)

However when only two images are bing used and no virtual position offsets, you may as well use -composite instead of -flatten, That is only one compose, when -flatten would be two, with an extra image creation.

Re: Composite with different transparencies

Posted: 2010-12-07T16:43:46-07:00
by anthony
Looking at the three images, rain, snow, and result, problem is that you want to retain transparency, but you want the 'snow' to completely replace the rain colors.

Questions:
* is the 'snow' always in the same areas as 'rain' as it in on your example images?
* do you want 'gray' areas, rather than say rain with the the snow numbers overlaid
* do you want a mix of the two images where they overlap?

To get what you expect it seems you either want one overlay image, or the other, without any mix between the two images. That seems to be a 'masked' merger.

Take the 'snow' image, and generate a black and white mask of the areas with snow. Blur it a little if you like a smoother transition. then do a three image composition to produce the merged result.
See http://www.imagemagick.org/Usage/compose/#mask

Re: Composite with different transparencies

Posted: 2010-12-07T16:47:46-07:00
by GreenKoopa
GreenKoopa wrote:I do notice that one image uses transparent black, the other transparent white.
I also notice that one image uses and indexed palette and the other doesn't. I don't see that either of these matter though.


Anthony:
anthony wrote:you may as well use -composite instead of -flatten, That is only one compose, when -flatten would be two, with an extra image creation.
Of course. I was trying to work around the unexpected black. What is suppose to happen when someone composites two transparent pixels? weatherbadger is getting black in one case and transparent in another. I don't see why, and he doesn't think he used to get the black.

Re: Composite with different transparencies

Posted: 2010-12-07T17:06:10-07:00
by anthony
For any Duff-Porter Alpha composition, transparent colors should never have any effect on the result... period. That is why their is only 12 combinations of color/transparency in the duff-porter set instead of 16.

See...
http://www.imagemagick.org/Usage/compose/#duff-porter

The default compose method 'Over' is a Duff-Porter Compose method.

Re: Composite with different transparencies

Posted: 2010-12-07T17:13:03-07:00
by weatherbadger
Composite worked for me previously and produces the sort of results as per my 3rd link.

In answer to your qus Anthony. Yes, the snow is opaque patches on a transparent background, not necessarily, and I think almost always where the rain is.
Rain is varying levels of transparent-opaque blue on a transparent background.
Not quite sure how you define mix, but as layers I want the snow image to go on top of the rain.

My suspicions are that the chart plotting software which gives a transparent background to the snow image has moved the transparency setting goalposts somehow... GreenKoopa - you said one uses transp white, and one transp black, and one indexed palette - not quite sure how to check that (or what it means!) but perhaps I can change that when the first images are created - that may be up to me then, but perhaps you can advise on how to check the difference between transparent black/white.

Like I said,

Code: Select all

composite USAsnow4.png transp_rain4.png finalimg.png
did work fine for a while so hopefully not too much head scratching required...

Re: Composite with different transparencies

Posted: 2010-12-07T17:19:29-07:00
by GreenKoopa
Anthony:
anthony wrote:For any Duff-Porter Alpha composition, transparent colors should never have any effect on the result... period. That is why their is only 12 combinations of color/transparency in the duff-porter set instead of 16.

See...
http://www.imagemagick.org/Usage/compose/#duff-porter

The default compose method 'Over' is a Duff-Porter Compose method.
Agreed, but I don't see how that explains where the black background comes from. None of the Duff-Porter methods show two transparent pixels turning black.

Re: Composite with different transparencies

Posted: 2010-12-07T17:34:28-07:00
by anthony
I doneloaded the snow image and found it has boolean transparency (either on or off, nothing between).

As such over should do the job, an no change should be needed.

the 'rain' image on the other had really does have a scale of transparency.
composite USAsnow4.png transp_rain4.png result.png
works perfectly fine for me.

However a recent change was that IM is attempting to generate smaller PNG pallette image (with multiple levels of alpha). However in this case it is failing to preserve alpha!!!!!

This is a known BUG but you should report this (as a new topic) the BUG forum with pointers to the original image, and probably to this post. Probably notify 'glennrp' of the PNG failure in this case. with a pointer to that BUG topic.

To stop IM from trying to generate 'bad' palette image try doing this instead
composite USAsnow4.png transp_rain4.png png32:result.png

Re: Composite with different transparencies

Posted: 2010-12-07T17:42:06-07:00
by GreenKoopa
Anthony's solution works great!!! I will write up the bug.
weatherbadger wrote: My suspicions are that the chart plotting software which gives a transparent background to the snow image has moved the transparency setting goalposts somehow... GreenKoopa - you said one uses transp white, and one transp black, and one indexed palette - not quite sure how to check that (or what it means!) but perhaps I can change that when the first images are created - that may be up to me then, but perhaps you can advise on how to check the difference between transparent black/white.
This apparently only mattered because of that bug.

> identify USAsnow4.png
USAsnow4.png PNG 600x600 600x600+0+0 8-bit PseudoClass 11c 12.3KB 0.000u 0:00.000
so an 11 color indexed palette

> identify transp_rain4.png
transp_rain4.png PNG 600x600 600x600+0+0 8-bit DirectClass 37.9KB 0.000u 0:00.000

As for the color of the transparency, I opened the images in Paint.NET and used the eyedropper. I'm sure other image editors will work. Transparent pixels can be black, white, any other color, and even vary from pixel to pixel. Sometimes this is for a reason, sometimes not. -alpha background can be used to set the color of transparency.

Re: Composite with different transparencies

Posted: 2010-12-07T18:08:10-07:00
by weatherbadger
BUG - oh my, that makes me feel just slightly less stupid than when I normally post here.

"Identify" - very useful.

However, the png32: which works for you but does not for me. Still getting black instead of transparent Hmmm... Is it an IM version thing?

Re: Composite with different transparencies

Posted: 2010-12-07T18:13:32-07:00
by GreenKoopa
I am using version 6.6.6-2 or 6.6.6-3. (seems to be some labeling confusion in this version)