Alpha compositing
Encyclopedia
In computer graphics
Computer graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer with help from specialized software and hardware....

, alpha compositing is the process of combining an image with a background to create the appearance of partial or full 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
Matte (filmmaking)
Mattes are used in photography and special effects filmmaking to combine two or more image elements into a single, final image. Usually, mattes are used to combine a foreground image with a background image . In this case, the matte is the background painting...

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.

Description

To store matte information, the concept of an alpha channel was introduced by Alvy Ray Smith
Alvy Ray Smith
Alvy Ray Smith III is an American engineer and noted pioneer in computer graphics. He is a co-founder of the animation studio Pixar.- Life and career :...

 in the late 1970s, and fully developed in a 1984 paper by Thomas Porter and Tom Duff
Tom Duff
Thomas Douglas Selkirk Duff is a computer programmer. He was born in Toronto, Ontario, Canada and grew up in Toronto and Leaside. In 1974 he graduated from the University of Waterloo with a B.Math and, two years later, got an M.Sc...

. In a 2D image element, which stores a color for each pixel, additional data is stored in the alpha channel with a value between 0 and 1. A value of 0 means that the pixel does not have any coverage information and is 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 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, to save on additional multiplications during compositing. This is usually referred to as premultiplied alpha.

Assuming that the pixel color is expressed using straight (non-premultiplied) RGBA tuples, a pixel value of (0.0, 0.5, 0.0, 0.5) implies a pixel which has 50% of the maximum green intensity and 50% opacity. If the color were fully green, its RGBA would be (0, 1, 0, 0.5).

However, if this pixel uses premultiplied alpha, all of the RGB values (0, 1, 0) are multiplied by 0.5 and then the alpha is appended to the end to yield (0, 0.5, 0, 0.5). In this case, the 0.5 value for the G channel actually indicates 100% green intensity (with 50% opacity). For this reason, knowing whether a file uses premultiplied or straight alpha is essential to correctly process or composite it.

Premultiplied alpha has some practical advantages over normal alpha blending because premultiplied alpha blending is associative
Associativity
In mathematics, associativity is a property of some binary operations. It means that, within an expression containing two or more occurrences in a row of the same associative operator, the order in which the operations are performed does not matter as long as the sequence of the operands is not...

 and linear interpolation
Linear interpolation
Linear interpolation is a method of curve fitting using linear polynomials. Lerp is an abbreviation for linear interpolation, which can also be used as a verb .-Linear interpolation between two known points:...

 gives better results, although premultiplication can cause a loss of precision and, in extreme cases, a noticeable loss of quality.

With the existence of an alpha channel, it is possible to express compositing image operations, using a compositing algebra. 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, held out by (usually abbreviated 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
Painter's algorithm
The painter's algorithm, also known as a priority fill, is one of the simplest solutions to the visibility problem in 3D computer graphics...

). The in operator is the alpha compositing equivalent of clipping
Clipping (computer graphics)
Any procedure which identifies that portion of a picture which is either inside or outside a picture is referred to as a clipping algorithm or clipping.The region against which an object is to be clipped is called clipping window.-Examples:...

.

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 the equation for output color as:

and resulting alpha channel value is

However, this operation may not be appropriate for all applications, since it is not associative.
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 merging of layers generally prefer this second approach.

Analytical derivation of the over operator

Porter and Duff gave a geometric interpretation of the alpha compositing formula by studying orthogonal coverages. Another derivation of the formula, based on a physical reflectance/transmittance
Transmittance
In optics and spectroscopy, transmittance is the fraction of incident light at a specified wavelength that passes through a sample. A related term is absorptance, or absorption factor, which is the fraction of radiation absorbed by a sample at a specified wavelength...

 model, can be found in a 1981 paper by Bruce A. Wallace.

A third approach is found by starting out with two very simple assumptions. For simplicity, we shall here use the shorthand notation for representing the over operator.

The first assumption is that in the case where the background is opaque (i.e. ), the over operator represents the convex combination
Convex combination
In convex geometry, a convex combination is a linear combination of points where all coefficients are non-negative and sum up to 1....

 of and :


The second assumption is that the operator must respect the associative rule:


Now, let us assume that and have variable transparencies, whereas is opaque. We're interested in finding
.

We know from the associative rule that the following must be true:


We know that is opaque and thus follows that is opaque, so in the above equation, each operator can be written as a convex combination:


Hence we see that this represents an equation of the form . By setting and we get

which means that we have analytically derived a formula for the output alpha and the output color of .

An even more compact representation is given by noticing that :


It is also interesting to note that the operator fulfills all the requirements of a non-commutative monoid
Monoid
In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single associative binary operation and an identity element. Monoids are studied in semigroup theory as they are naturally semigroups with identity. Monoids occur in several branches of mathematics; for...

, where the identity element
Identity element
In mathematics, an identity element is a special type of element of a set with respect to a binary operation on that set. It leaves other elements unchanged when combined with them...

  is chosen such that (i.e. the identity element can be any tuple with .)

Alpha blending

Alpha blending is a convex combination
Convex combination
In convex geometry, a convex combination is a linear combination of points where all coefficients are non-negative and sum up to 1....

 of two color
Color
Color or colour is the visual perceptual property corresponding in humans to the categories called red, green, blue and others. Color derives from the spectrum of light interacting in the eye with the spectral sensitivities of the light receptors...

s allowing for transparency
Transparency (graphic)
Transparency is possible in a number of graphics file formats. The term transparency is used in various ways by different people, but at its simplest there is "full transparency" i.e. something that is completely invisible. Of course, only part of a graphic should be fully transparent, or there...

 effects in computer graphics. The value of 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. This corresponds to "SRC over DST" in Porter and Duff equations.

The value of the resulting color is given by:


If the destination background is opaque, then , and if you enter it to the upper equation:


The alpha component may be used to blend to red
Red
Red is any of a number of similar colors evoked by light consisting predominantly of the longest wavelengths of light discernible by the human eye, in the wavelength range of roughly 630–740 nm. Longer wavelengths than this are called infrared , and cannot be seen by the naked eye...

, green
Green
Green is a color, the perception of which is evoked by light having a spectrum dominated by energy with a wavelength of roughly 520–570 nanometres. In the subtractive color system, it is not a primary color, but is created out of a mixture of yellow and blue, or yellow and cyan; it is considered...

 and blue
Blue
Blue is a colour, the perception of which is evoked by light having a spectrum dominated by energy with a wavelength of roughly 440–490 nm. It is considered one of the additive primary colours. On the HSV Colour Wheel, the complement of blue is yellow; that is, a colour corresponding to an equal...

 components equally, as in 32-bit
32-bit
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....

 RGBA
RGBA color space
RGBA stands for Red Green Blue Alpha. While it is sometimes described as a color space, it is actually simply a use of the RGB color model, with extra information. The color is RGB, and may belong to any RGB color space, but an integral alpha value as invented by Catmull and Smith between 1971 and...

, or, alternatively, there may be three alpha values specified corresponding to each of the primary color
Primary color
Primary colors are sets of colors that can be combined to make a useful range of colors. For human applications, three primary colors are usually used, since human color vision is trichromatic....

s for spectral color
Spectral color
A spectral color is a color that is evoked by a single wavelength of light in the visible spectrum, or by a relatively narrow band of wavelengths...

 filtering
Filter (optics)
Optical filters are devices which selectively transmit light of different wavelengths, usually implemented as plane glass or plastic devices in the optical path which are either dyed in the mass or have interference coatings....

.

Note that the RGB color may be premultiplied, hence saving the additional multiplication before RGB in the equation above. This can be a considerable saving in processing time given that images are often made up of millions of pixels.

Other transparency methods

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 a 1-bit alpha channel, as found in the 16-bit RGBA Highcolor mode of the Truevision TGA
Truevision TGA
Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc. . It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible PCs to support Highcolor/truecolor display...

 image file format and related TARGA
Targa
Targa is an old word for targe, shield. Targa or TARGA may also refer to:Car rallies*Targa Florio, Sicily, Italy*Targa Canada West, Canada*Targa New Zealand*Targa Newfoundland, Canada*Targa Tasmania, Australia*Targa West, Western Australia...

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

For some applications, a single alpha channel is not sufficient: a stained-glass window, for instance, requires a separate transparency channel for each RGB channel to model the red transparency, green transparency, and blue transparency. More alpha channels can be added for accurate spectral color filtration applications.

Applications

Alpha blending is used in a variety of applications. It is natively supported by most operating systems/GUIs for drawing windows (where applicable) or widgets:
  • AmigaOS 4.1
  • Android
  • BeOS
    BeOS
    BeOS is an operating system for personal computers which began development by Be Inc. in 1991. It was first written to run on BeBox hardware. BeOS was optimized for digital media work and was written to take advantage of modern hardware facilities such as symmetric multiprocessing by utilizing...

    , magnussoft ZETA, Haiku
    Haiku (operating system)
    Haiku is a free and open source operating system compatible with BeOS. Its development began in 2001, and the operating system became self-hosting in 2008, with the first alpha release in September 2009, the second in May 2010 and the third in June 2011....

  • Inferno
    Inferno (operating system)
    Inferno is a distributed operating system started at Bell Labs, but is now developed and maintained by Vita Nuova Holdings as free software. Inferno was based on the experience gained with Plan 9 from Bell Labs, and the further research of Bell Labs into operating systems, languages, on-the-fly...

  • Mac OS X
    Mac OS X
    Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

    , iOS
  • MorphOS
    MorphOS
    MorphOS is an Amiga-compatible computer operating system. It is a mixed proprietary and open source OS produced for the Pegasos PowerPC processor based computer, PowerUP accelerator equipped Amiga computers, and a series of Freescale development boards that use the Genesi firmware, including the...

  • Plan 9
    Plan 9 from Bell Labs
    Plan 9 from Bell Labs is a distributed operating system. It was developed primarily for research purposes as the successor to Unix by the Computing Sciences Research Center at Bell Labs between the mid-1980s and 2002...

  • QNX
    QNX
    QNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market. The product was originally developed by Canadian company, QNX Software Systems, which was later acquired by Canadian BlackBerry-producer Research In Motion.-Description:As a microkernel-based...

     Neutrino
  • RISC OS Adjust
  • Syllable
    Syllable (operating system)
    Syllable Desktop is a free and open source operating system for Pentium and compatible processors. Its purpose is to create an easy-to-use desktop operating system for the home and small office user...

  • webOS
  • Windows 2000
    Windows 2000
    Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...

     or later, CE
    Windows CE
    Microsoft Windows CE is an operating system developed by Microsoft for embedded systems. Windows CE is a distinct operating system and kernel, rather than a trimmed-down version of desktop Windows...

    , Mobile
    Windows Mobile
    Windows Mobile is a mobile operating system developed by Microsoft that was used in smartphones and Pocket PCs, but by 2011 was rarely supplied on new phones. The last version is "Windows Mobile 6.5.5"; it is superseded by Windows Phone, which does not run Windows Mobile software.Windows Mobile is...

  • The XRender
    XRender
    The X Rendering Extension is an X Window System extension to implement Porter-Duff image compositing in the X server, to allow efficient display of transparent images.- History :...

     extension to the X Window System
    X Window System
    The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

     (this includes modern UNIX
    Unix
    Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

     and Linux
    Linux
    Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

     systems)
  • GNOME
    GNOME
    GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. It is composed entirely of free and open source software...

     3.0
  • Unity
    Unity (user interface)
    Unity is a shell interface for the GNOME desktop environment developed by Canonical Ltd for its Ubuntu operating system. Unity debuted in the netbook edition of Ubuntu 10.10. It is designed to make more efficient use of space given the limited screen size of netbooks, including, for example, a...

  • KDE
    KDE
    KDE is an international free software community producing an integrated set of cross-platform applications designed to run on Linux, FreeBSD, Microsoft Windows, Solaris and Mac OS X systems...

     (4.0 or later)
  • Xfce
    Xfce
    Xfce is a free software desktop environment for Unix and other Unix-like platforms, such as Linux, Solaris, and BSD – though recent compatibility issues have arisen with regard to BSD Unix platforms...



Other software may use alpha blended transparent elements in the GUI independently of OS provided APIs by precomposing elements in an off-screen memory buffer before displaying them. (Such as when displaying partially transparent composited elements in an embedded system which provides only a simple frame buffer.) Compositing software
Compositing software
A software that is used in Post Production to composit scenes in a film and for adding Motion Graphics, special effects and color correction.-Layer Based:This software uses a Layer based interface for compositing and visual effects...

 is used to combine images, and makes extensive use of alpha compositing techniques.

See also

  • RGBA color space
    RGBA color space
    RGBA stands for Red Green Blue Alpha. While it is sometimes described as a color space, it is actually simply a use of the RGB color model, with extra information. The color is RGB, and may belong to any RGB color space, but an integral alpha value as invented by Catmull and Smith between 1971 and...

  • Digital compositing
    Digital compositing
    Digital compositing is the process of digitally assembling multiple images to make a final image, typically for print, motion pictures or screen display...

  • Transparency (graphic)
    Transparency (graphic)
    Transparency is possible in a number of graphics file formats. The term transparency is used in various ways by different people, but at its simplest there is "full transparency" i.e. something that is completely invisible. Of course, only part of a graphic should be fully transparent, or there...

  • Transparent color in palettes
  • Image masks
  • Portable Network Graphics
  • Truevision TGA
    Truevision TGA
    Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc. . It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible PCs to support Highcolor/truecolor display...

  • Magic Pink
  • Texture splatting
    Texture Splatting
    In computer graphics, texture splatting is a method for combining different textures. The method works by applying an alphamap to the higher levels, revealing the layers underneath where the alphamap is partially or completely transparent...

  • Alpha to coverage
    Alpha to coverage
    Alpha to coverage is a multisampling computer graphics technique useful for situations where dense foliage or grass must be rendered in a video game.This technique uses the alpha channel of textures as a coverage mask for anti-aliasing....


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK