HOME

TheInfoList



OR:

In
computer graphics Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
, alpha compositing or alpha blending is the process of combining one image with a background to create the appearance of partial or full transparency. It is often useful to render picture elements (pixels) in separate passes or layers and then combine the resulting 2D images into a single, final image called the
composite Composite or compositing may refer to: Materials * Composite material, a material that is made from several different substances ** Metal matrix composite, composed of metal and other parts ** Cermet, a composite of ceramic and metallic material ...
. Compositing is used extensively in
film A film, also known as a movie or motion picture, is a work of visual art that simulates experiences and otherwise communicates ideas, stories, perceptions, emotions, or atmosphere through the use of moving images that are generally, sinc ...
when combining computer-rendered image elements with live footage. Alpha blending is also used in 2D computer graphics to put
rasterized In computer graphics, rasterisation (British English) or rasterization (American English) is the task of taking an image described in a vector graphics format (shapes) and converting it into a raster image (a series of pixels, dots or lines, whic ...
foreground elements over a background. In order to combine the picture elements of the images correctly, it is necessary to keep an associated ''
matte Matte may refer to: Art * paint with a non-glossy finish. See diffuse reflection. * a framing element surrounding a painting or watercolor within the outer frame Film * Matte (filmmaking), filmmaking and video production technology * Matte pai ...
'' for each element in addition to its color. This matte layer contains the coverage information—the shape of the geometry being drawn—making it possible to distinguish between parts of the image where something was drawn and parts that are empty. Although the most basic operation of combining two images is to put one over the other, there are many operations, or
blend modes Blend modes (alternatively blending modes or mixing modes) in digital image editing and computer graphics are used to determine how two Layers (digital image editing), layers are blended with each other. The default blend mode in most applications ...
, that are used.


History

The concept of an alpha channel was introduced by
Alvy Ray Smith Alvy Ray Smith III (born September 8, 1943) is an American computer scientist who co-founded Lucasfilm's Computer Division and Pixar, participating in the 1980s and 1990s expansion of computer animation into feature film. He is one of the 50 F ...
and Ed Catmull in the late 1970s at the
New York Institute of Technology Computer Graphics Lab The Computer Graphics Lab is a computer lab located at the New York Institute of Technology (NYIT), founded by Alexander Schure. It was originally located at the "pink building" on the NYIT campus. It has played an important role in the history ...
. Bruce A. Wallace derived the same straight over operator based on a physical
reflectance The reflectance of the surface of a material is its effectiveness in reflecting radiant energy. It is the fraction of incident electromagnetic power that is reflected at the boundary. Reflectance is a component of the response of the electronic ...
/
transmittance Electromagnetic radiation can be affected in several ways by the medium in which it propagates.  It can be Scattering, scattered, Absorption (electromagnetic radiation), absorbed, and Fresnel equations, reflected and refracted at discontinui ...
model in 1981. A 1984 paper by Thomas Porter and
Tom Duff Thomas Douglas Selkirk Duff (born December 8, 1952) is a Canadian computer programmer. Life and career Early life Duff was born in Toronto, Ontario, Canada, and was named for his putative ancestor, the fifth Earl of Selkirk. He grew up in Tor ...
introduced premultiplied alpha using a geometrical approach. The use of the term ''alpha'' is explained by Smith as follows: "We called it that because of the classic linear interpolation formula \alpha A + (1-\alpha)B that uses the Greek letter \alpha (alpha) to control the amount of interpolation between, in this case, two images A and B". That is, when compositing image A atop image B, the value of \alpha in the formula is taken directly from A's alpha channel.


Description

In a 2D image a color combination is stored for each picture element (pixel), often a combination of red, green and blue (
RGB The RGB color model is an additive color model in which the red, green, and blue primary colors of light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three ...
). When alpha compositing is in use, each pixel has an additional numeric value stored in its alpha channel, with a value ranging from 0 to 1. A value of 0 means that the pixel is fully transparent and the color in the pixel beneath will show through. A value of 1 means that the pixel is fully opaque. With the existence of an alpha channel, it is possible to express compositing image operations using a ''compositing algebra''. For example, given two images ''A'' and ''B'', the most common compositing operation is to combine the images so 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 (the phrase refers to holdout matting and is 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: As an example, the over operator can be accomplished by applying the following formula to each pixel: :\begin\alpha_o &= \phantom\alpha_a + \phantom\alpha_b(1 - \alpha_a) \\ C_o &= \frac \end Here C_o, C_a and C_b stand for the color components of the pixels in the result of the "over", image A, and image B respectively, applied to each color channel (red/green/blue) individually, whereas \alpha_o, \alpha_a and \alpha_b are the alpha values of the respective pixels. The over operator is, in effect, the normal painting operation (see
Painter's algorithm The painter's algorithm (also depth-sort algorithm and priority fill) is an algorithm for Hidden-surface determination#Visible surface determination, visible surface determination in 3D computer graphics that works on a polygon, polygon-by-polyg ...
). The in and out operators are the alpha compositing equivalent of
clipping Clipping may refer to: Words * Clipping (morphology), the formation of a new word by shortening it, e.g. "ad" from "advertisement" * Clipping (phonetics), shortening the articulation of a speech sound, usually a vowel * Clipping (publications ...
. The two use only the alpha channel of the second image and ignore the color components. In addition, plus defines additive blending.


Straight versus premultiplied

If an alpha channel is used in an image, there are two common representations that are available: straight (unassociated) alpha and premultiplied (associated) alpha. * With straight alpha, the RGB components represent the color of the object or pixel, disregarding its opacity. This is the method implied by the over operator in the previous section. * With premultiplied alpha, the RGB components represent the emission of the object or pixel, and the alpha represents the occlusion. The over operator then becomes: *:C_o = C_a + C_b(1 - \alpha_a) *:\alpha_o = \alpha_a + \alpha_b(1 - \alpha_a)


Comparison

The most significant advantage of premultiplied alpha is that it allows for correct blending,
interpolation In the mathematics, mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points. In engineering and science, one ...
, and
filtering Filtration is a physical process that separates solid matter and fluid from a mixture. Filter, filtering, filters or filtration may also refer to: Science and technology Computing * Filter (higher-order function), in functional programming * Fil ...
. Ordinary interpolation without premultiplied alpha leads to RGB information leaking out of fully transparent (A=0) regions, even though this RGB information is ideally invisible. When interpolating or filtering images with abrupt borders between transparent and opaque regions, this can result in borders of colors that were not visible in the original image. Errors also occur in areas of semitransparency because the RGB components are not correctly weighted, giving incorrectly high weighting to the color of the more transparent (lower alpha) pixels. Premultiplied alpha may also be used to allow regions of regular alpha blending (e.g. smoke) and regions with additive blending mode (e.g. flame and glitter effects) to be encoded within the same image. This is represented by an RGBA triplet that express emission with no occlusion, such as (0.4, 0.3, 0.2, 0.0). Another advantage of premultiplied alpha is performance; in certain situations, it can reduce the number of multiplication operations (e.g. if the image is used many times during later compositing). The Porter–Duff operations have a simple form only in premultiplied alpha. Some rendering pipelines expose a "straight alpha" API surface, but converts them into premultiplied alpha for performance. One disadvantage of premultiplied alpha is that it can reduce the available relative precision in the RGB values when using integer or fixed-point representation for the color components. This may cause a noticeable loss of quality if the color information is later brightened or if the alpha channel is removed. In practice, this is not usually noticeable because during typical composition operations, such as OVER, the influence of the low-precision color information in low-alpha areas on the final output image (after composition) is correspondingly reduced. This loss of precision also makes premultiplied images easier to
compress compress is a Unix shell compression program based on the LZW compression algorithm. Compared to gzip's fastest setting, compress is slightly slower at compression, slightly faster at decompression, and has a significantly lower compression ...
using certain compression schemes, as they do not record the color variations hidden inside transparent regions, and can allocate fewer bits to encode low-alpha areas. The same “limitations” of lower quantisation bit depths such as 8 bit per channel are also present in imagery without alpha, and this argument is problematic as a result.


Examples

Assuming that the pixel color is expressed using ''straight'' (non-premultiplied) RGBA
tuple In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is o ...
s, a pixel value of (0, 0.7, 0, 0.5) implies a pixel that has 70% 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, 0.7, 0) are multiplied, or scaled for occlusion, by the alpha value 0.5, which is appended to yield (0, 0.35, 0, 0.5). In this case, the 0.35 value for the G channel actually indicates 70% green emission intensity (with 50% occlusion). A pure green emission would be encoded as (0, 0.5, 0, 0.5). Knowing whether a file uses straight or premultiplied alpha is essential to correctly process or composite it, as a different calculation is required. Emission with no occlusion cannot be represented in straight alpha. No conversion is available in this case.


Image formats supporting alpha channels

The most popular image formats that support the alpha channel are PNG and
TIFF Tag Image File Format or Tagged Image File Format, commonly known by the abbreviations TIFF or TIF, is an image file format for storing raster graphics images, popular among graphic artists, the publishing industry, and photographers. TIFF is w ...
.
GIF The Graphics Interchange Format (GIF; or , ) is a Raster graphics, bitmap Image file formats, image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite and released ...
supports alpha channels, but is considered to be inefficient when it comes to file size. Support for alpha channels is present in some video codecs, such as Animation and Apple ProRes 4444 of the QuickTime format, or in the Techsmith multi-format codec. The
file format A file format is a Computer standard, standard way that information is encoded for storage in a computer file. It specifies how bits are used to encode information in a digital storage medium. File formats may be either proprietary format, pr ...
BMP generally does not support this channel; however, in different formats such as 32-bit (888–8) or 16-bit (444–4) it is possible to save the alpha channel, although not all systems or programs are able to read it: it is exploited mainly in some video games or particular applications; specific programs have also been created for the creation of these BMPs.


Gamma correction

The RGB values of typical digital images do not directly correspond to the physical light intensities, but are rather compressed by a
gamma correction Gamma correction or gamma is a Nonlinearity, nonlinear operation used to encode and decode Relative luminance, luminance or CIE 1931 color space#Tristimulus values, tristimulus values in video or still image systems. Gamma correction is, in the s ...
function: : C_\text = C_\text^ This transformation better utilizes the limited number of bits in the encoded image by choosing \gamma that better matches the non-linear human perception of luminance. Accordingly, computer programs that deal with such images must decode the RGB values into a linear space (by undoing the gamma-compression), blend the linear light intensities, and re-apply the gamma compression to the result: :''C_o = \left(\frac{ C_a^\gamma \alpha_a + C_b^\gamma \alpha_b (1 - \alpha_a) }{\alpha_o}\right)^{1/\gamma}'' When combined with premultiplied alpha, pre-multiplication is done in linear space, prior to gamma compression. This results in the following formula: :C_o = \left( C_a^\gamma + C_b^\gamma (1 - \alpha_a) \right)^{1/\gamma} Note that the alpha channel may or may not undergo gamma-correction, even when the color channels do.


Other transparency methods

Although used for similar purposes, transparent colors and
image mask In computer science, a mask or bitmask is data that is used for bitwise operations, particularly in a bit field. Using a mask, multiple bits in a byte, nibble, word, etc. can be set either on or off, or inverted from on to off (or vice versa) in ...
s 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 high color mode of the
Truevision TGA Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc. (now part of Avid Technology). It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible ...
image file format An image file format is a file format for a digital image. There are many formats that can be used, such as JPEG, PNG, and GIF. Most formats up until 2022 were for storing 2D images, not 3D ones. The data stored in an image file format may be co ...
and related TARGA and AT-Vista/NU-Vista display adapters' high color graphic mode. This mode devotes 5 bits for every primary RGB color ( 15-bit RGB) plus a remaining bit as the "alpha channel".
Dither Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is ofte ...
ing can be used to simulate partial occlusion where only 1-bit alpha is available. For some applications, a single alpha channel is not sufficient: a
stained-glass window Stained glass refers to coloured glass as a material or art and architectural works created from it. Although it is traditionally made in flat panels and used as windows, the creations of modern stained glass artists also include three-dimensio ...
, for instance, requires a separate transparency channel for each RGB channel to model the red, green and blue transparency separately. More alpha channels can be added for accurate spectral color filtration applications. Some
order-independent transparency Order-independent transparency (OIT) is a class of techniques in rasterization, rasterisational computer graphics for rendering Transparency (graphic), transparency in a 3D scene, which do not require rendering geometry in sorted order for alpha co ...
methods replace the over operator with a commutative approximation.


See also


References


External links


Compositing Digital Images - Thomas Porter and Tom Duff (Original Paper)

Image Compositing Fundamentals

Understand Compositing and Color extensions in SVG 1.2 in 30 minutes!

Alpha Matting and Premultiplication
{{DEFAULTSORT:Alpha Compositing Computer graphics algorithms