The math of over and keymix – Apple Shake 4 User Manual
Page 424
424
Chapter 15
Image Processing Basics
If you ignore the premultiplication of your composites, you may have problems with
edges, or with raised global levels. Many people see these types of errors, and assume
it is a mask problem, so they pinch in the mask a bit. Even more extreme people have
erroneously assumed you cannot color correct premultiplied images. These problems
are easily solved through proper management of premultiplication.
The Math of Over and KeyMix
To understand why premultiplication problems occur, it is best to cut straight to the
heart of compositing by understanding how a standard composite operator (foreground
through a mask over a background) works. This has nothing to do with Shake, but in
fact was worked out in the 1970s by two clever fellows named Porter and Duff.
The following is the math equation they developed. In this equation, A is the
foreground’s alpha channel:
Comp = (Fg * A) + ((1-A)*Bg)
Rather than go into this too deeply, look briefly at the significant part,
(Fg*A)
. This is
the definition of premultiplication—“RGB multiplied by its alpha.” To avoid the math,
you can build the composite with other nodes, in effect constructing an Over node
from scratch.
The following example (continued from the above section) shows how to build the
compositing equation.
To build the compositing equation:
1
Read in the munch_unpremult.jpg and munch_mask.iff images from the /Tutorial_Misc/
premult directory.
The munch_unpremult image is an unpremultiplied image. It has no mask, so there is
no correspondence between black pixels in the RGB channels and black pixels in the
mask to describe transparency in the image.
2
The first step in the formula is (
Fg*A
). To duplicate this using nodes, attach an IMult
node to munch_unpremult and connect the munch_mask node to the IMult background
input.
munch_unpremult.jpg
munch_mask.iff