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 correctly combine these image elements, it is necessary to keep
an associated ''[[matte]]'' for each element. This matte contains the coverage information — the shape of the geometry being drawnmaking it possible to distinguish between parts of the image where the geometry was actually drawn and other parts of the image which are empty.

To store this matte information, the concept of an '''alpha channel''' was introduced
by [[Alvy Ray Smith|A.R.Smith]] in the late 1970s, and fully developed in a 1984 paper by [[Thomas Porter]] and [[Tom Duff]].<ref>Thomas Porter and Tom Duff, '''Compositing Digital Images''', ''Computer Graphics'', '''18'''(3), July 1984, 253-259. [http://dx.doi.org/10.1145/800031.808606 DOI:10.1145/800031.808606]</ref> In a 2D image element which stores a color for each pixel, an additional value is stored in the alpha channel containing a value ranging from 0 to 1. A value of 0 means that the pixel does not have any coverage information and is fully transparent; i.e. there was no color contribution from any geometry because the geometry did not overlap this pixel. A value of 1 means that the pixel is fully opaque because the geometry completely overlapped the pixel.

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

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:

[[Image
:Alpha compositing.svg]]

The '''over''' operator is, in effect, the normal painting operation (see [[Painter's algorithm]]). The '''in''' operator is the alpha compositing equivalent of [[Clipping (computer graphics)|clipping]].

As an example, the '''over''' operator
can be accomplished by applying the following formula to each pixel value:

:<math>C_o = C_a \alpha_a + C_b \alpha_b \left(1 - \alpha_a\right)</math>

:<math>\alpha_o = \alpha_a + \alpha_b \left(1 - \alpha_a\right)</math>

where C<sub>o</sub> is the result of the operation, C<sub>a</sub> is the color of the pixel in element A, C<sub>b</sub> is the color of the pixel in element B, and α<sub>a</sub> and α<sub>b</sub> are the alpha of the pixels in elements A and B respectively.

This operator may not be appropriate for all applications, however, since it is not [[associative
]].
An alternate color composition commonly used in image applications that allows reordering of layer applications is:

:<math>\alpha_o = \alpha_a + \alpha_b \left(1 - \alpha_a\right)</math>
:<math>C_o = \frac{\alpha_a C_a + \left(1 - \alpha_a\right)\alpha_b C_b}{\alpha_o}</math>

Note that if it is assumed that all color values
are premultiplied by their alpha values (c = αC), we can write this as:

:<math>c_o = c_a + \left(1 - \alpha_a\right) c_b</math>


Alpha compositing on images can be done in most graphics programs.

==Alpha blending==
Alpha blending is a [[convex combination]] of two [[color]]s allowing for [[Transparency (graphic)|transparency]] effects in [[computer graphic]]s. The value of <code>alpha</code> 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 <code>Value1</code> with an alpha value of <
math>\alpha</math> is drawn over an opaque background of color <code>Value0</code> is given by:

:<
math>Value=\left(1 - \alpha\right) Value_0 + \alpha Value_1</math>

The alpha component may be used to blend to [[red]], [[green]] and [[blue]] components equally, as in [[32-bit]] [[RGBA color space|RGBA]], or, alternatively, there may be three alpha values specified corresponding to each of the [[primary color]]s for [[spectral color]] [[filter (optics)|filtering]].

Alpha blending is natively supported by these operating systems/GUIs:
* [[Mac OS X]]
* [[Windows 2000]], [[Windows XP|XP
]], [[Windows Server 2003|Server 2003]], and [[Windows Vista|Vista]]
* The [[XRender]] extension to the [[X Window System]] (this includes modern [[Linux]] systems)
* [[RISC OS|RISC OS Adjust]]
* [[QNX Neutrino]]
* [[Plan 9 from Bell Labs|Plan 9]]
* [[Inferno operating system|Inferno]]

==References==
{{reflist
}}

==See also==
*[[RGBA color space]]
*[[Digital compositing]]
*[[Portable Network Graphics]]
*[[Magic Pink]]

[[Category:Computer graphics]]

[[cs:Alfa kanál]]
[[de:Alphakanal]]
[[fr:Alpha blending]]
[[ko:알파 채널]]
[[ja:アルファチャンネル]]
[[pt:Canal alfa
]]
[[ru:Альфа-канал]]
[[fi:Alfakanava]]
[[zh:阿尔法通道]]