Hi! I'm working with a number of PNG images which have a 0% alpha background. However, some parts of the image have other alpha levels. I want to create a new image which ignores the 0% alpha, but combines the other alpha levels with an RGB value of my choosing. The idea is that I can remove any colour with alpha that "touches" the background of the image so that it's a pure colour of one form or another. Is there any tool within IM that allow this or would this require some custom coding ?
Thanks!
[SOLVED] Custom logic for alpha blending
[SOLVED] Custom logic for alpha blending
Last edited by comper on 2013-01-24T03:34:42-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Custom logic for alpha blending
Not sure what you really want, but just copy the alpha channel and composite onto another image of the background you want.
Please clarify what you want under the 0% alpha and what you want under the other alpha values.
Please clarify what you want under the 0% alpha and what you want under the other alpha values.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Custom logic for alpha blending
FX may be useful. See:
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx
snibgo's IM pages: im.snibgo.com
[SOLVED] Re: Custom logic for alpha blending
Thanks, snibgo! That's precisely the sort of thing I was looking at!
Thanks again
c
Thanks again
c
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: [SOLVED] Custom logic for alpha blending
Ignoring the alpha (fully transparent) areas of an image is typically done by multiplying all colors by the alpha channel, before blending. Afterwards the colors are divided by not only the blend amounts (typically number of pixels involved) but also the alpha values (number of partial pixels blended together).
The result is that semi-transparent colors are handled properly, but all resulting fully transparent pixels will become full-transparent black.
Almost all IM operators do this. This includes... Resize, Distorts, Scales, Compositions, Convolution, Morphology, Blur, and operations involving 'fuzz' factors, (color replacement, animation frame optimization)
Operations which do not handle transparency include: auto-level, normalize, FX (you have to DIY it), and if the channel 'Sync' flag is disabled: mathematical compositions, and convolution.
NOTE Comparison (except for a 'fuzz metric') does not do anything special with regards to alpha channel.
And even with 'fuzz' metric, it only equates transparency as equivalent, It does not ignore comparisons on color to transparent, which would be useful for 'overly match' or 'masked sub-image search'.
The result is that semi-transparent colors are handled properly, but all resulting fully transparent pixels will become full-transparent black.
Almost all IM operators do this. This includes... Resize, Distorts, Scales, Compositions, Convolution, Morphology, Blur, and operations involving 'fuzz' factors, (color replacement, animation frame optimization)
Operations which do not handle transparency include: auto-level, normalize, FX (you have to DIY it), and if the channel 'Sync' flag is disabled: mathematical compositions, and convolution.
NOTE Comparison (except for a 'fuzz metric') does not do anything special with regards to alpha channel.
And even with 'fuzz' metric, it only equates transparency as equivalent, It does not ignore comparisons on color to transparent, which would be useful for 'overly match' or 'masked sub-image search'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/