Premultiplication

From RMIT Visual Effects
Jump to: navigation, search

DEAR LORD!!!... there is NOTHING that causes more problems for students of Nuke (and their teachers) than premultiplication. No matter how carefully it is explained, students often dont know how to use it, or use it badly. Several of the items in the script structure page refer to the perils of poorly managed premultiplication. First, here is why premultiplication is needed:

What is premultiplication and why it is needed

All images consist of values that extend from black to white (the three color channels being simply grey-scale images) and these values can be expressed as numbers: 1 for white, 0 for black, .5 for mid grey etc. The problem is that there is no natural value in a digital image for transparency. However, with simple maths we can 'fake' it. First of all we need:

A background (BG), a foreground (FG) and an alpha (A)

Premult 1.png


Now listen...

  • 1 X any number = no change
  • 0 X any number = 0

From that we can say:

  • The white values (1) in A multiplied by the FG will effect no change upon the FG.
  • The black values (0) in A multiplied by the FG will turn the FG black.

In the example below, the mask has been multiplied over the photo of the girl. See how the white values of the mask have no effect on the photo, whilst the black values turn it black.

Premult 2.png


Now invert A so that its black values and white values are 'swopped'. Perform the same multiplication over the BG. See how in the example below, the inverted mask makes a girl shaped black region in the landscape.

Premult 3.png


Now more maths:

  • 0 + any number = no change

So....

  • The blacks values (0) in the BG will effect no change upon the FG values.
  • The blacks values (0) in the FG will effect no change upon the BG values.

This gives us a FG plus a BG that looks like (voila!):

Premult 4.png

The example .psd file is in the Assets page (apologies, the alpha is a bit rough).

What happens if premultiplication is not handled well

If premultiplication is not handled well then the maths fails. The following are the main dangers:

  • If the black of the premultiplied FG is lightened (for example: as a result of a color adjustment), then it will brighten the BG.
This is not a good thing. In the image below the ball was lightened but the color correction of the one on the right was not preceded by an unpremultiply (Unpremult). In the process the black premultiplied background was also lightened which affected the color of the composite.

Premultbad 2.png

  • If (in the process of poorly managed premultiplication workflow) the grey of the soft edges is darkened or lightened then the edges of the composite will be noisy.
This is not a good thing. In the image below the ball on the right was premultiplied twice. This imparted a dark rim to the edge of the ball (soft edges are very vulnerable to this sort of thing).

Premultbad 1.png

The main places this these screw-ups occur is whilst the FG is being color edited or merged:

Merging

The standerd workflow for dealing with premultiplication whist merging is simple:

  1. Derive an alpha from the FG
  2. Premultiply FG by A
  3. Merge (add) FG with BG

This translates as:

- PREMULTIPLICATION LAW WHILST MERGING -
When it is time for the FG and BG to be merged together then the FG MUST be in a premultiplied state.
Also... DON'T premultiply the same image twice.



Color editing

This is wrong:

Premultiplied image --> Color edit

Such a workflow could badly effect the black values of the premultiplied image. The solution is to unpremultiply before the color edit, like this:

Premultiplied image --> Unpremultiplied image --> Color edit --> Premultiply

Therefore:

- PREMULTIPLICATION LAW WHILST COLOR EDITING -
DONT perform any color edit on the FG if it has been premultiplied.



Premult and Unpremult

The Premult and Unpremult nodes are the workhorses of the premultiplaction workflow. Premult will premultiply an image (asuming it has an alpha), Unpremult will unpremultiply it.

Merging and Premultiplication Dos and Dont's

The following is a summery of the dos and dont's of premultiplication.

Don't color correct premultiplied images

Color correction should not be done on images that are premultiplied. To un-premultiply you may use an Unpremult node, or use the (un)premult option within the node.

The (un)premult parameter of a color node.

Don't composite pre-multiplied images

Don't Don't composite a FG that is not pre-multiplied

Don't Double pre-multiplication

Do not apply premultiplication twice in a row to the same image. It can damage the edges of the alpha.

Color adjust only RGB

By default all color adjustments work on the alpha of an image as well as the RGB. Almost always this is not a good thing and can really screw up a comp. Set the color adjustment to RGB only.

The top color node is adjusting the RGBA of an image, the bottom is only adjusting the RGB(which is generally preferred).

Donʼt use the composite image that comes out of a keyer

Most high end keyers output a composite image (the foreground over the background). generally, this should not be used, as no color corrections can be done to the foreground. Better instead to use the keyer's alpha channel ina merging operation further down the node tree.