Log in

View Full Version : Premultiplied Alpha


NoX1911
18th November 2003, 04:24
Hi,
whats the right way to show premultiplied alpha bitmaps in avisynth?

clip=AviSource("video.avi").ConvertToRGB32
pic=ImageReader("pic.bmp").ConvertToRGB32
Layer(clip,pic,"add",255)
This works great with straight alpha but leaves grey border on premultiplied alpha.
Any suggestions? :confused:

Richard Berg
18th November 2003, 05:27
Can you clarify what you mean by premultiplied alpha? Only thing coming to mind: I forget offhand whether converting a YUV clip to RGB32 will set the alpha channel appropriately.

NoX1911
18th November 2003, 15:09
Different alpha blending methods:
http://www.ledet.com/coolstuff/software/aftereffects/alphachannel.pdf

Example:
http://mitglied.lycos.de/heldimzelt1638/alpha.gif
Straight, Premultiplied and alpha channel

Blending results (using VirtualDub Logo filter):
http://mitglied.lycos.de/heldimzelt1638/alpha2.gif
**** (Overlay Pic/Blending method) ****
Left: Premultiplied/Premultiplied or straight/straight
Center: Premultiplied/Straight
Right: Straight/Premultiplied

'Left' is the only correct blending. The script posted is intended for straight blending only. Premultiplied pics result in 'dark edges' (look center pic above) and need additional processing (dont know.. negative multiplication or something to brighten edges...).

sh0dan
18th November 2003, 15:55
Technically:

When there is variable alpha levels (better-than-gif transparency), the image is sometimes stored with a solid color as background color. When the background color is known the "real" color of the transparent pixel can be recreated.

Creating "premultiplied alpha" (free from memory):

transparency = 0.0 to 1.0, 0.0 being transparent, 1.0 being non-transparent.

final_pixel = (realcolor*transparency) + (bgcolor*(1.0-transparency))

Recreating the pixel:

realcolor = ((bg_color*(1.0-transparency)) - pixel_color) / transparency

NoX1911
18th November 2003, 20:23
There is no avisynth command allowing such per-pixel processing atm, right?

Maybe a good solution would be to implement it directly in the 'layer' command...

:sly:

sh0dan
19th November 2003, 00:00
Originally posted by HeldImZelt
There is no avisynth command allowing such per-pixel processing atm, right?
No.

Maybe a good solution would be to implement it directly in the 'layer' command...
The best idea would probably be to implement it as a separate filter, that allows the original transparent image to be recreated.