maximum density instead of accumulation

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
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

maximum density instead of accumulation

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post 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
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post 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).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post 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.
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post by fmw42 »

indiego wrote: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.

I cannot see how to download these files!
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post by indiego »

Looks like I made an unlucky decision when selecting the picture hoster. Never done this before, epic fail... :D
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...).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post 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?
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post 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).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post 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?
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: maximum density instead of accumulation

Post 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
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post by indiego »

fmw42 wrote: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
Thanks again. I will try this out. :mrgreen:
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: maximum density instead of accumulation

Post 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
Post Reply