Understanding Premultiplied Images

Premultiplied images are one of the most confusing and undocumented areas of computer graphics.

A premultiplied image is simply an image where the alpha (a) channel has been premultiplied by the colour (RGB)
a * RGB
We know in maths that anything multiplied by black or 0 equals zero
i.e. 5 x 0 = 0
and anything multiplied by white or 1 is unchanged,
i.e. 5 x 1 = 5
and finally anything multiplied by 0.5 is half its original value.
i.e. 5 x 0.5 = 2.5

In CG terms, this applies to how the Alpha and RGB relate to each other, specifically anti-aliasing / semi transparent edges. Any value of 0 or 1 is not affected.

So:

preMult01

whereas…

preMult02

Two questions that spring to mind are:

Firstly, how does the premultiplied state get set?
The answer is that it’s done by the software when saving the image.

And secondly, which software packages default to premultiplied and which to unpremultiplied?

preMult03

When it comes to managing how images deal with Premultiplied Alpha, Nuke, Fusion and Shake have two useful nodes: ‘Unpremult’ and ‘Premult’. The ‘Premult’ node multiplies the RGB by the Alpha. The ‘Unpremult’ node divides the RGB by the Alpha. When compositing images together you always have to be careful to make sure the images are correctly Premultiplied. For example, when compositing images with an Over operation:

If you think your image is Unpremultiplied (but it’s really Premultiplied) and you add a Premult node you basically multiply the image twice (RGB x Alpha x Alpha). If you have an RGB pixel of 0.6 and you multiply it by the alpha pixel of 0.4 you get a correct value of 0.24 for that RGB pixel. But if you premultiply the image twice you are effectively doing 0.6 x 0.4 x 0.4 giving you a value of 0.096, which darkens the edge.

preMult04

On the other hand, if you think your image is Premultiplied (but it’s really Unpremultiplied) and you therefore do not add a Premult node, the composite will have a light area where the alpha pixels are white.

preMult05

There are situations when you will want to Unpremultiply an image. The general rule for any form of colour correction is: Unpremult the image first, do the colour correction and then Premult back to its correct state. This is so you don’t accidentally colour correct any of the transparent Alpha edges.

One final thing to note is that if you Read in a non-Linear coloured image, sRGB for instance, which contains an Alpha channel such as a 3D render, you need to make sure you Unpremultiply the image before doing the LUT conversion. This basically Unpremultiplies, then converts the colourspace from sRGB (in the example) to Linear, then Premultiplies it back to its original stage. Again, as with colour correction, this stops the transparent Alpha edges getting damaged during the colour space conversion.