In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial transparency. It is often useful to render image elements in separate passes, and then combine the resulting multiple 2D images into a single, final image in a process called compositing. For example, compositing is used extensively when combining computer rendered image elements with live footage.
In order to combine these image elements correctly, it is necessary to keep an associated matte for each element. This matte contains the coverage information — the shape of the geometry being drawn — making it possible to distinguish between parts of the image where the geometry was actually drawn and other parts of the image which are empty.
If an alpha channel is used in an image, it is common to also multiply the color by the alpha value, in order to save on additional multiplications during the compositing process. This is usually referred to as premultiplied alpha. Thus, assuming that the pixel color is expressed using RGB triples, a pixel value of (0.0, 0.5, 0.0, 0.5) implies a pixel which is fully green and has 50% coverage. (Explanation: The RGB values are the first three values, (0, 0.5, 0) and the alpha value is the fourth, 0.5. If the color were fully green, its RGB would be (0, 1, 0). Since this pixel is using a premultiplied alpha, all of the RGB values in the ordered triplet (0, 1, 0) are multiplied by 0.5 and then the alpha is added to the end to yield (0, 0.5, 0, 0.5). )
With the existence of an alpha channel, it is then easy to express useful compositing image operations, using a compositing algebra defined in the Duff and Porter paper. For example, given two image elements A and B, the most common compositing operation is to combine the images such that A appears in the foreground and B appears in the background; this can be expressed as A over B. In addition to over, Porter and Duff defined the compositing operators in, out, atop, and xor (and the reverse operators rover, rin, rout, and ratop) from a consideration of choices in blending the colors of two pixels when their coverage is, conceptually, overlaid orthogonally:
The over operator is, in effect, the normal painting operation (see Painter's algorithm). The in operator is the alpha compositing equivalent of clipping.
As an example, the over operator can be accomplished by applying the following formula to each pixel value:
where is the result of the operation, is the color of the pixel in element A, is the color of the pixel in element B, and and are the alpha of the pixels in elements A and B respectively. If it is assumed that all color values are premultiplied by their alpha values (), we can rewrite this as:
However, this operation may not be appropriate for all applications, since it is not associative (i.e. it matters whether you first add object A and then object B or first B and then A. For example when building a picture from 3 color-channels it should not take effect in which order you add them, but with this non-associative version it would.). The associative version of this operation is very similar; simply take the newly computed color value and divide it by its new alpha value, as follows:
Image editing applications that allow reordering of layers generally prefer this second approach.
alpha in the color code ranges from 0.0 to 1.0, where 0.0 represents a fully transparent color, and 1.0 represents a fully opaque color.The value of the resulting color when color Value1 with an alpha value of is drawn over an opaque background of color Value0 is given by:
The alpha component may be used to blend to red, green and blue components equally, as in 32-bit RGBA, or, alternatively, there may be three alpha values specified corresponding to each of the primary colors for spectral color filtering.
Alpha blending is natively supported by these operating systems/GUIs:
Although used for similar purposes, transparent colors and image masks do not permit the smooth blending of the superimposed image pixels with those of the background (only whole image pixels or whole background pixels allowed).
A similar effect can be achieved with an 1-bit alpha channel, as found in the 16-bit RGBA Highcolor mode of the Truevision TGA image file format and related TARGA and AT-Vista/NU-Vista display adapters' Highcolor graphic mode. This mode devotes 5 bits for every primary RGB color (15-bit RGB) plus a remaining bit as the "alpha channel".