[SOLVED] Custom logic for alpha blending

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
comper
Posts: 2
Joined: 2013-01-23T09:34:50-07:00
Authentication code: 6789

[SOLVED] Custom logic for alpha blending

Post by comper »

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!
Last edited by comper on 2013-01-24T03:34:42-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Custom logic for alpha blending

Post by fmw42 »

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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Custom logic for alpha blending

Post by snibgo »

snibgo's IM pages: im.snibgo.com
comper
Posts: 2
Joined: 2013-01-23T09:34:50-07:00
Authentication code: 6789

[SOLVED] Re: Custom logic for alpha blending

Post by comper »

Thanks, snibgo! That's precisely the sort of thing I was looking at!

Thanks again :)

c
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] Custom logic for alpha blending

Post by anthony »

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'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply