Premultiplication

From Nuke Learning
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:

Contents

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...

From that we can say:

As below:

Premult 2.png


Now invert A so that its black values and white values are 'swopped'. Perform the same multiplication over the BG.

Premult 3.png


Now more maths:

So....

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:

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

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 and other tools

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

Within many nodes there is a premult parameter. It is there to save on the hassle of top and tailing the color operations with Premult and Unpremult nodes. If ticked it will unpremult and premult entirely within the confines of the node. It is not efficiant to use this parameter on long chains of complex color edits as the premultiplication is always being turned off and on, but for for simple, singular edits it is fine.

Premult param.png

See also

Some examples of good and bad premultiplication are in the Assets page.

Personal tools
Namespaces
Variants
Actions
Intro
Important
Workflows
Other
Print/export
Toolbox