WorryFree Computers   »   [go: up one dir, main page]

ALPHA COMPOSITING

In computer graphics:

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 called the composite. For example, compositing is used extensively when combining computer-rendered image elements with live footage.
Related imageIn 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 that are empty.
To store matte information, the concept of an alpha channel was introduced by Alvin Ray Smith in the late 1970s, and fully developed in a 1984 paper by Thomas Porter and Tom Duff. In a 2D image element, which stores a colour 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 colour 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, there are two common representations that are available: straight (unassociated) alpha and pre multiplied (associated) alpha.

With straight alpha, the RGB components represent the colour of the object or pixel, disregarding its opacity.
With premultiplied alpha, the RGB components represent the emission of the object or pixel, and the alpha represents the occlusion. A more obvious advantage of this is that, in certain situations, it can save a subsequent multiplication (e.g. if the image is used many times during later compositing). However, the most significant advantages of using premultiplied alpha are for correctness and simplicity rather than performance: premultiplied alpha allows correct filtering and blending. In addition, premultiplied alpha allows regions of regular alpha blending and regions with additive blending mode to be encoded within the same image, because channel values are usually stored in a fixed-point format which bounds the values to be between 0 and 1.
Image result for ALPHA COMPOSITINGAssuming that the pixel colour is expressed using straight (non-premultiplied) RGBA tuples, 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 colour were fully green, its RGBA would be (0, 1, 0, and 0.5).
However, if this pixel uses premultiplied alpha, all of the RGB values (0, 0.7, 0) are as though they were scaled for occlusion by 0.5 and then the alpha is appended to the end 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, and 0.5). For this reason, knowing whether a file uses straight or premultiplied alpha is essential to correctly process or composite it as a different formula is used. It is also entirely acceptable to have an RGBA triplet express emission with no occlusion, such as (0.4, 0.3, 0.2, and 0.0). Fires and flames, glows, flares, and other such phenomena can only be represented using associated / premultiplied alpha.
The only important difference is in the dynamic range of the colour representation in finite precision numerical calculations (which is in all applications): premultiplied alpha has a unique representation for transparent pixels, avoiding the need to choose a “clear colour” or resultant artefacts such as edge fringes (see the next paragraphs). In an associated / premultiplied alpha image, the RGB represents the emission amount, while the alpha is occlusion. Premultiplied alpha has some practical advantages over normal alpha blending because interpolation and filtering give correct results.
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 colours that were not visible in the original image. Errors also occur in areas of semi transparency because the RGB components are not correctly weighted, giving incorrectly high weighting to the colour of the more transparent (lower alpha) pixels.
Pre multiplication can reduce the available relative precision in the RGB values when using integer or fixed-point representation for the colour components, which may cause a noticeable loss of quality if the colour 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 colour 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 using certain compression schemes, as they do not record the colour variations hidden inside transparent regions, and can allocate fewer bits to encode low-alpha areas.
Image result for ALPHA COMPOSITINGWith the existence of an alpha channel, it is possible to express compositing image operations using 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 or (and the reverse operators rover, rin, rout, and ratop) from a consideration of choices in blending the colours of two pixels when their coverage is, conceptually, overlaid orthogonally.
Alpha blending is the process of combining a translucent foreground colour with a background colour, thereby producing a new blended colour. The degree of the foreground colour’s translucency may range from completely transparent to completely opaque. If the foreground colour is completely transparent, the blended colour will be the background colour. Conversely, if it is completely opaque, the blended colour will be the foreground colour. The translucency can range between these extremes, in which case the blended colour is computed as a weighted average of the foreground and background colours.