Page 1 of 1
maximum density instead of accumulation
Posted: 2010-10-29T01:43:30-07:00
by indiego
Hi,
I compose a semitransparent graphic containing all the light effects. All subgraphics use pure white with varying density values. My problem now is that I want no accumulation of the density values in the overlaping areas. What I need instead is the maximal density value.
Just an example to make it clear. Picture A has a density of 50%, picture B has a density of 25%. Where they overlap I get an density of 62.5%, but what I want is a density of 50%. How can this be done?
Peter
Re: maximum density instead of accumulation
Posted: 2010-10-29T09:49:59-07:00
by fmw42
-compose lighten or -evaluate-sequence
will take all the images and at each pixel find that image with the brightest value and use that in the output
see
http://www.imagemagick.org/Usage/compose/#lighten
http://www.imagemagick.org/script/comma ... e-sequence
convert image1 image2 image3 ... imageN -evaluate-sequence max result
or
convert image1 image2 image3 ... imageN -compose lighten -layers merge result
Re: maximum density instead of accumulation
Posted: 2010-10-29T10:59:49-07:00
by indiego
Thanks for the fast reply. I tried it with my example pictures and got unwanted side effect. I have two pictures.
picture A with a circle in color rgba(255,255,255,127) and
picture B fully painted in rgba(255,255,255,63).
After combining them I want rgba(255,255,255,127) for the circle area and rgba(255,255,255,63) for the rest of the picture.
Using 'lighten' gives me a fully opaque picture with the circle in rgba(159,159,159,255) and the background in rgba(63,63,63,255).
Using 'evaluate-sequence max' gives me rgba(255,255,255,192) for the circle and an opaque background of rgba(255,255,255,255).
Do I have to separate the alpha channels for this kind of operation? That should work with lighten (as I understand it).
Re: maximum density instead of accumulation
Posted: 2010-10-29T13:13:14-07:00
by fmw42
Can you post links to your images and describe what you want for the result. I am having trouble visualizing what you desire.
Re: maximum density instead of accumulation
Posted: 2010-10-29T13:27:22-07:00
by indiego
I understand that (I even got confused writing this mess down).
http://z47.img-up.net/?up=circle3tksp.png
http://f59.img-up.net/?up=squaretlgxh.png
The images are not visible as they use transparent white only, but it is possible to save them.
Re: maximum density instead of accumulation
Posted: 2010-10-29T16:10:50-07:00
by fmw42
I cannot see how to download these files!
Re: maximum density instead of accumulation
Posted: 2010-10-30T02:56:58-07:00
by indiego
Looks like I made an unlucky decision when selecting the picture hoster. Never done this before, epic fail...
If you can give me a tip for a better hoster I will use that one the next time.
Anyhow, you can download the pictures if you save them over the right mouse button menu (save picture as...).
Re: maximum density instead of accumulation
Posted: 2010-10-30T11:02:04-07:00
by fmw42
OK. I was able to get your images. try
convert squaretlgxh.png circle3tksp.png -compose over -composite circle_over_square.png
Is that what you want?
Re: maximum density instead of accumulation
Posted: 2010-10-31T08:01:51-07:00
by indiego
fmw42 wrote:OK. I was able to get your images. try
convert squaretlgxh.png circle3tksp.png -compose over -composite circle_over_square.png
Is that what you want?
Nope, that is exactly what I currently have. Check out the alpha value of the circle in the resulting picture. The white has a density of 62.5%, which is the accumulation of both density values. What I want is a density of 50% for the circle area (maximum of 50% and 25%) and 25% for the rest (no intersection here).
Re: maximum density instead of accumulation
Posted: 2010-10-31T13:31:01-07:00
by fmw42
I am confused. I thought you wanted the opaque areas to have certain values. Sounds more like you want the alpha channel to have certain values. Could you please clarify further exactly what you are trying to do. Sorry if you are repeating but I am confused now.
I thought all you wanted was the circle brightness to replace the square brightness where ever the circle was located and leave the square brightness alone elsewhere?
Re: maximum density instead of accumulation
Posted: 2010-11-01T08:55:30-07:00
by indiego
fmw42 wrote:I am confused. I thought you wanted the opaque areas to have certain values. Sounds more like you want the alpha channel to have certain values. Could you please clarify further exactly what you are trying to do. Sorry if you are repeating but I am confused now.
I thought all you wanted was the circle brightness to replace the square brightness where ever the circle was located and leave the square brightness alone elsewhere?
You are right with your assumption, that I wanted to have specific values in the alpha channel. The color part is pure white only for all the lighting and black with fully transparency for all unaffected areas.
Anyhow, in the meantime I have learned about the use of "-channel RGBA" in combination with "-blur" and transparency, which solves my prior problems with the overlaping areas. I get no ugly hard borders anymore and the resulting graphics have the wanted effect. So I followed the wrong track and there is no real need for such a function anymore.
Just for the records: I thought about using "-channel RGB picA.png picB.png -composite" to combine the color part and "-channel A picA.png picB.png -compose lighten -composite" for the alpha channel. That should give the wanted effect, but how to combine the color channels and the alpha channel again? A ask just out of interest.
fmw42, sorry for confusing you and thanks for all your help!
Greetings, Peter
Re: maximum density instead of accumulation
Posted: 2010-11-01T10:31:32-07:00
by fmw42
to put an alpha channel into an RGB image
convert image alphachannel -alpha off -compose copy_opacity -composite result
see
http://www.imagemagick.org/Usage/compose/#copyopacity
Re: maximum density instead of accumulation
Posted: 2010-11-01T10:38:36-07:00
by indiego
Thanks again. I will try this out.

Re: maximum density instead of accumulation
Posted: 2010-11-01T11:08:56-07:00
by indiego
Thanks, works as expected.
convert -channel RGB square.png circle.png -composite +matte colorchannel.png
convert -channel A square.png circle.png -compose lighten -composite alphachannel.png
convert colorchannel.png alphachannel.png -compose copy_opacity -composite result.png