Premultiplied


#1

Hi guys,
I read the part about premultiplying alpha channels in Art and Science of Dig Comp and I understand it is a bad thing and what it basically does. My question is when do I know its premultiplied? I render a seperate pass out of my 3d app for alpha channels and then in After Effects I apply the matte. Then I add a blur or something and I get the dreaded black line. Am I wrong in assuming that my matte wasnt premultiplied since I rendered it seperate? Thanks in advance.


#2

The premultiply option, produces an antialiasing effect on your Alpha channel, but in msot cases against a black background on your software, be it 3D or Post software. You can change the default colour but I recommend dont use pre multply, spcially if you will use that alpha against bright backgrounds, they are more notorious then. On your composite package jsut premultiply or not your imported footage depends on what you see, some softwres does automatically, like AFx, others you smut premultiply manually, like DF.
On your 3D software jsut disable the premultiply option, and export with Alpha channel. looking at first you will see a weird countour on your footage, but that s better , to composite, because the post softwre can antialias the alpha edge agains YOUR footage ann not against a flat colour.
I am not quite sure but some 3D and 2D softwares can premultply against a given background , but I dotn think is a good idea either, you will enter not necessary colour correction issues then. premultply can be used often to produce textures to real time engines, transparencies, etc. Also to web aplciations adn any otehr operation that requires built-in antialiasing for alpha channels.


#3

I suppose this isn’t always the case, but if your object is rendered out against black, and it has nice smooth antialiased edges against the black, it’s likely premultplied with the alpha channel. You can how ever, like the good book says, divide out the alpha channel and mostly get an un-premultiplied image. That’s best done against black, colors are just harder, so don’t do that.


#4

Premultiplying works just fine as long as you don’t plan to do heavy grading in post production (and as long as you indicate in the compositing programme, that the clip is premultiplied).

Taking out the background color of antialiased image data, based on the transparency of the alpha channel, is an equation that will give a wrong result if the image data is changed after rendering.

Cheers,

  • Jonas

#5

Just need to comment here. Premultiply is not bad, it is actually the “one true way” of alpha channels. The discusting “straight alpha” used by some compositing software is what is the true evil and the implementation of the compositing software being of “straight alpha” type is what prevents premultiplied alpha from working correctly.

/Z


#6

I feel a religious war coming on here… :slight_smile:

Could you please elaborate on exactly why straight alphas are evil and prevent premultiplied alphas from working correctly?

Since I switched to rendering straight alphas, compositing with ambient occlusion, sunlight passes and texture color correction has become so much easier and better.

Cheers,

  • Jonas

#7

Well in all honesty, I’m teasing a bit. :wink:

In premultiplied alpha, a color which contains a color, but alpha zero, is actually legal. This combination will actually be composited additively, since the equation is

result = background * (1-forgeround.alpha) + foreground

Many compositing software can’t handle this because internally the work with straight alphas, which is

result = background * (1-forgeround.alpha) + foreground * foreground.alpha

Hence such a “special” color in premultiplied where RGB>A is completely impossible to represent as a straight alpha color, causing some issues.

The fact that calculations happen in straight is also the cause of all these issues of, for example, black edges on a blur and whatnot. If you did all calculations internally in premultiplied, there would be no such issues!

But all the problems you are having with premultiplied is due to the fact the software is using straight internally. It was straight internally, I’d say most of these issues go away.

/Z


#8

OK, you’re not as mad as I thought, then. :wink:

I agree compositing software should be able to handle premultiplied better, After Effects is particularly stupid in that area. (there is no “right-click -> unpremultiply”)

3D Studio Max is also nuts. The documentation praises and recommends rendering 3d images with premultiplied alphas, but God curse you if you try to use a premultiplied texture map! 3dsmax’s material editor can only handle straight alphas. -Yes, there is a “premultipled” check box, but that will only help you if you want to composite the image onto another image or color in the shader, but not you if want to use the alpha to make the object transparent…

In the state of the world we live in, straight alphas are your friend, but yes, programs ought to just be able to handle premultiplied just as well, the math behind it is painfully simple.

  • Jonas

#9

Don’t be sure about that :wink:

I agree compositing software should be able to handle premultiplied better, After Effects is particularly stupid in that area. (there is no “right-click -> unpremultiply”)
True, but that’s not where the problem is. The problem lies in that the layer stack itself is implemented in “straight” mode.

3D Studio Max is also nuts. The documentation praises and recommends rendering 3d images with premultiplied alphas, but God curse you if you try to use a premultiplied texture map!

They are quite right there.

You see, straight alphas comes from a tradition of masking and working with an underlying real photo or picture which already contains picture data all over the frame and you want to “extract” something. In this case alpha is like a “switch” which switches between foreground (alpha=1) and background (alpha=0).

Premultiplied alpha comes from a tradition of rendering where the concept of truly transparent pixels exist, i.e. they are not black, they are transparent, which is different. In this case alpha is opacity, i.e. how much of the background is let through, and it does not, in no way, affect the foreground.

For this reason, in some cases, for example, when working with things like greenscreened footage, “straigth” is clearly better, because you can later “recover” a pixel that was badly keyed by just painting in some alpha again. In “premultiplied” alpha a gone pixel is gone forever into 0,0,0,0 transparent.

For stuff coming from a “rendered” side, premultiplied is preffered because it encodes true transparency information.

The two things are really separate things. It’s a pity they’ve both been smacked into this one concept of “alpha”. They are “masks” and “transparency” respectively.

3dsmax’s material editor can only handle straight alphas. -Yes, there is a “premultipled” check box, but that will only help you if you want to composite the image onto another image or color in the shader, but not you if want to use the alpha to make the object transparent…
That’s true. Unfortunately.

In the state of the world we live in, straight alphas are your friend, but yes, programs ought to just be able to handle premultiplied just as well, the math behind it is painfully simple.

Agree. Ideally, this should be a switchable mode in a compositing program, both within a layer, and in how the “layer stack” operates.

/Z


#10

I’d have to differ on a couple counts here.

I’d say, the problem is not with the software, but with the preconceived notion of what is going on in the software. There’s no “straight” mode or premultiplied mode way of doing things. There is only the mathematical way in which the compositing equations work out and through many years of industry research, it is proven that non-premultiplied alphas/mattes TYPICALLY give the best results for MOST compositing tasks because of the USUAL requirement of color correction.

I don’t know about these “truly transparent pixels”. Certainly the intent is to make them transparent, but then so is bluescreen. It just happens they are blue until they are, hmmm… premultiplied to black by a matte/alpha (hopefully after color correction) before being added to a premultiplied background.

I wouldn’t say premultiplied is preferred in general. Maybe preferred by you because there is less work when no color correction is done. But non-premultiplied allows for much needed flexibility and color correction without halos prior to compositing.

The point is, there is no right or wrong way for an alpha/matte to be, it just depends on what you are using it for at any give time.


#11

Is it really that hard to unpremultiply an image before you color correct and then premultiply it after? Ive been doing it this way for years. It’s not exactly rocket science.


#12

Here’s three legal premultiplied colors, please give me the “unpremuliplied” equivalent:

R=1.0
G=1.0
B=1.0
A=0.5

R=0.5
G=0.5
B=0.5
A=0.0

R=0.2
G=0.3
B=0.4
A=0.1

waiting interested :wink:

/Z


#13

The formula for un-premultiplying image data is simply
[left]
new color = original color/alpha value
[/left]

-the problem (for me) is doing that in a app like After Effects. I think I have three threads on the AE board where I ask about just that, but to this day it still doesn’t seem possible.

Cheers,

  • Jonas

#14

A 0,0,0,0 premultiplied pixel is a 100% transparent pixel.

I wouldn’t say premultiplied is preferred in general. Maybe preferred by you because there is less work when no color correction is done.
I do not understand why premultiplied works any less for color corrections.

There is some bizarre idea that an edge pixel are color-corrected “better” if they are somehow un-anti-aliased. E.g. a yellow object that covers half the pixel should for some reason be treated not as a 50% yellow object, but as a 100% yellow object that covers half the pixel when working at the EDGE of the object, but when a yellow object is next to a black object within the object, it will be a 50% yellow pixel, and then it’s somehow “all right”? I don’t get why the anti-aliased edge should be treated differently than the anti aliased interior of the image.

If thats what you want you should do all color correction on the subpixel level, not the pixel level.

/Z


#15

I know. Please apply it to the numbers I gave and tell me which colors you get :wink:

(To do it in AE there is a free UnMult plugin)

/Z


#16

…and I don’t see how those are legal premultiplied colors.

In a premultiplied image, by definition, the average of the color values can’t be above the alpha value. (supposed the background color is black, but since you didn’t mention it, that’s what I assumed :wink: )

  • Jonas

#17

Wrong; That is a completely legal additive premultiplied color. Thats a great feature of premultiplied alphas (the built in mix between “over” and “add” compositing within the color itself), which all the “straight alpha” apps butcher. To the point of making the claim that you just did, that those colors are not “legal”. (There is an amusing passage in the AE manual about just that, merrily proclaiming these colors “not legal”)

Sure, very few softwares actually uses this feature, but the feature IS there. Like for example 3DS max renders it’s glows with such alpha management.

/Z


#18

“If you look at the math that is used when we premultiply an image by a matte, it should be obvious that the brightness of any given red, green or blue channel in such an image can never exceed the value of the alpha channel”

Ron Brinkmann, “The Art and Science of Digital Compositing”, p. 75


#19

…I understand what you’re saying about the additive data in a premultiplied image, but since it does go against basic alpha theory, we can only hope that more apps will use this feature in the future, and perform the necessary math on premultiplied alphas. :slight_smile:

  • Jonas

#20

Sure, but it’s still wrong. :smiley:

I talked to Alvy Ray Smith, the guy who invented the alpha channel together with Ed Catmull, and he agrees with me :wink:

…I understand what you’re saying about the additive data in a premultiplied image, but since it does go against basic alpha theory, we can only hope that more apps will use this feature in the future, and perform the necessary math on premultiplied alphas
AE has the mode “luminous premultiplied” but it doesn’t work together with any effect, ONLY as a “layer mode” for the raw data with no effects applied.

/Z