Sponsored Links

Senin, 01 Januari 2018

Sponsored Links

Compositing with Transparency | Kdenlive
src: kdenlive.org

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.

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 that are empty.


Video Alpha compositing



Description

To store matte information, the concept of an alpha channel was introduced by Alvy 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 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, 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.

With premultiplied alpha, the RGB components represent the color of the object or pixel, adjusted for its opacity by multiplication. 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.

Assuming that the pixel color 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 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 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 intensity (with 50% opacity). Fully green would be encoded as (0, 0.5, 0, 0.5). For this reason, knowing whether a file uses straight or premultiplied alpha is essential to correctly process or composite it.

It is often said that associativity is an advantage of pre-multiplied alpha blending over straight alpha blending, but both are associative. 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 color" or resultant artefacts such as edge fringes (see the next paragraphs). In other words, color information of transparent pixels is lost in premultiplied alpha, as the conversion from premultiplied alpha to straight alpha is undefined for alpha equal to zero. 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 colors that were not visible in the original image. Errors also occur in areas of semitransparancy because the RGB components are not correctly weighted, giving incorrectly high weighting to the color of the more transparent (lower alpha) pixels.

Premultiplication can reduce the available relative precision in the RGB values when using integer or fixed-point representation for the color components, which 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 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 color variations hidden inside transparent regions, and can allocate fewer bits to encode low-alpha areas.

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). 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:

C o = C a ? a + C b ? b ( 1 - ? a ) ? a + ? b ( 1 - ? a ) {\displaystyle C_{o}={\frac {C_{a}\alpha _{a}+C_{b}\alpha _{b}\left(1-\alpha _{a}\right)}{\alpha _{a}+\alpha _{b}\left(1-\alpha _{a}\right)}}}

where C o {\displaystyle C_{o}} is the result of the operation, C a {\displaystyle C_{a}} is the color of the pixel in element A, C b {\displaystyle C_{b}} is the color of the pixel in element B, and ? a {\displaystyle \alpha _{a}} and ? b {\displaystyle \alpha _{b}} 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 ( c i = ? i C i {\displaystyle c_{i}=\alpha _{i}C_{i}} ), we can rewrite the equation for output color as:

c o = c a + c b ( 1 - ? a ) {\displaystyle c_{o}=c_{a}+c_{b}\left(1-\alpha _{a}\right)}

and resulting alpha channel value is

? o = c o C o = ? a + ? b ( 1 - ? a ) {\displaystyle \alpha _{o}={\frac {c_{o}}{C_{o}}}=\alpha _{a}+\alpha _{b}\left(1-\alpha _{a}\right)}

Examples

Examples of red overlaid with green with both colours fully opaque:


Maps Alpha compositing



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 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 a ? b {\displaystyle a\odot b} for representing the over operator.

The first assumption is that in the case where the background is opaque (i.e. ? b = 1 {\displaystyle \alpha _{b}=1} ), the over operator represents the convex combination of a {\displaystyle a} and b {\displaystyle b} :

C o = ? a C a + ( 1 - ? a ) C b {\displaystyle C_{o}=\alpha _{a}C_{a}+(1-\alpha _{a})C_{b}}

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

( a ? b ) ? c = a ? ( b ? c ) {\displaystyle (a\odot b)\odot c=a\odot (b\odot c)}

Now, let us assume that a {\displaystyle a} and b {\displaystyle b} have variable transparencies, whereas c {\displaystyle c} is opaque. We're interested in finding

o = a ? b {\displaystyle o=a\odot b} .

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

o ? c = a ? ( b ? c ) {\displaystyle o\odot c=a\odot (b\odot c)}

We know that c {\displaystyle c} is opaque and thus follows that b ? c {\displaystyle b\odot c} is opaque, so in the above equation, each ? {\displaystyle \odot } operator can be written as a convex combination:

? o C o + ( 1 - ? o ) C c = ? a C a + ( 1 - ? a ) ( ? b C b + ( 1 - ? b ) C c ) = ? a C a + ( 1 - ? a ) ? b C b + ( 1 - ? a ) ( 1 - ? b ) C c {\displaystyle {\begin{aligned}\alpha _{o}C_{o}+(1-\alpha _{o})C_{c}&=\alpha _{a}C_{a}+(1-\alpha _{a})(\alpha _{b}C_{b}+(1-\alpha _{b})C_{c})\\&=\alpha _{a}C_{a}+(1-\alpha _{a})\alpha _{b}C_{b}+(1-\alpha _{a})(1-\alpha _{b})C_{c}\end{aligned}}}

Hence we see that this represents an equation of the form X 0 + Y 0 C c = X 1 + Y 1 C c {\displaystyle X_{0}+Y_{0}C_{c}=X_{1}+Y_{1}C_{c}} . By setting X 0 = X 1 {\displaystyle X_{0}=X_{1}} and Y 0 = Y 1 {\displaystyle Y_{0}=Y_{1}} we get

? o = 1 - ( 1 - ? a ) ( 1 - ? b ) , C o = ? a C a + ( 1 - ? a ) ? b C b ? o , {\displaystyle {\begin{aligned}\alpha _{o}&=1-(1-\alpha _{a})(1-\alpha _{b}),\\C_{o}&={\frac {\alpha _{a}C_{a}+(1-\alpha _{a})\alpha _{b}C_{b}}{\alpha _{o}}},\end{aligned}}}

which means that we have analytically derived a formula for the output alpha and the output color of a ? b {\displaystyle a\odot b} .

An even more compact representation is given by noticing that ( 1 - ? a ) ? b = ? o - ? a {\displaystyle (1-\alpha _{a})\alpha _{b}=\alpha _{o}-\alpha _{a}} :

C o = ? a ? o C a + ( 1 - ? a ? o ) C b {\displaystyle C_{o}={\frac {\alpha _{a}}{\alpha _{o}}}C_{a}+\left(1-{\frac {\alpha _{a}}{\alpha _{o}}}\right)C_{b}}

It is also interesting to note that the ? {\displaystyle \odot } operator fulfills all the requirements of a non-commutative monoid, where the identity element e {\displaystyle e} is chosen such that e ? a = a ? e = a {\displaystyle e\odot a=a\odot e=a} (i.e. the identity element can be any tuple ? C , ? ? {\displaystyle \langle C,\alpha \rangle } with ? = 0 {\displaystyle \alpha =0} .)


Alpha Over Node รข€
src: docs.blender.org


Alpha blending

Alpha blending is the process of combining a translucent foreground color with a background color, thereby producing a new blended color. The degree of the foreground color's translucency may range from completely transparent to completely opaque. If the foreground color is completely transparent, the blended color will be the background color. Conversely, if it is completely opaque, the blended color will be the foreground color. Of course, the translucency can range between these extremes, in which case the blended color is computed as a weighted average of the foreground and background colors.

Alpha blending is a convex combination of two colors allowing for transparency 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 alpha value also corresponds to the ratio of "SRC over DST" in Porter and Duff equations.

The value of the resulting color is given by:

{ o u t A = s r c A + d s t A ( 1 - s r c A ) o u t R G B = ( s r c R G B s r c A + d s t R G B d s t A ( 1 - s r c A ) ) ÷ o u t A o u t A = 0 => o u t R G B = 0 {\displaystyle {\begin{cases}\mathrm {out} _{A}=\mathrm {src} _{A}+\mathrm {dst} _{A}(1-\mathrm {src} _{A})\\\mathrm {out} _{RGB}={\bigl (}\mathrm {src} _{RGB}\mathrm {src} _{A}+\mathrm {dst} _{RGB}\mathrm {dst} _{A}\left(1-\mathrm {src} _{A}\right){\bigr )}\div \mathrm {out} _{A}\\\mathrm {out} _{A}=0\Rightarrow \mathrm {out} _{RGB}=0\end{cases}}}

If the destination background is opaque, then d s t A = 1 {\displaystyle dst_{A}=1} , and if you enter it to the upper equation:

{ o u t A = 1 o u t R G B = s r c R G B s r c A + d s t R G B ( 1 - s r c A ) {\displaystyle {\begin{cases}\mathrm {out} _{A}=1\\\mathrm {out} _{RGB}=\mathrm {src} _{RGB}\mathrm {src} _{A}+\mathrm {dst} _{RGB}(1-\mathrm {src} _{A})\end{cases}}}

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.

If pre-multiplied alpha is used, the above equations are simplified to:

{ o u t A = s r c A + d s t A ( 1 - s r c A ) o u t R G B = s r c R G B + d s t R G B ( 1 - s r c A ) {\displaystyle {\begin{cases}\mathrm {out} _{A}=\mathrm {src} _{A}+\mathrm {dst} _{A}(1-\mathrm {src} _{A})\\\mathrm {out} _{RGB}=\mathrm {src} _{RGB}+\mathrm {dst} _{RGB}\left(1-\mathrm {src} _{A}\right)\end{cases}}}

Compositing with Transparency | Kdenlive
src: kdenlive.org


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


Bright Blue Ink In Water Or Smoke With Alpha Mask For Motion ...
src: thumbs.dreamstime.com


See also

  • Bit blit
  • RGBA color space
  • Digital compositing
  • Transparency (graphic)
  • Transparent color in palettes
  • Image masks
  • Portable Network Graphics
  • Truevision TGA
  • Magic Pink
  • Texture splatting
  • Alpha to coverage

Compositing with Transparency | Kdenlive
src: kdenlive.org


References


Palm trees flowing in the wind,Alpha included for easier ...
src: buidln.clipdealer.com


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

Source of the article : Wikipedia

Comments
0 Comments