User:Lkesteloot/premultiplied alpha

Premultiplied alpha (or alpha premultiplication) is a method for storing semi-transparent colors in images in order to speed up subsequent alpha compositing during digital compositing. Note that the name implies that the alpha channel is premultipled, but this is misleading. It's the color channels that are premultiplied by the alpha channel.

Colors in RGBA images can be stored normally or premultiplied by the alpha channel. For example, a pixel that's full red (1,0,0) and has a 50% alpha (0.5), can be stored with premultiplied colors (0.5,0,0,0.5) or with non-premultiplied colors (1,0,0,0.5).

There are advantages to both schemes. For example, with non-premultiplied colors, the opacity of an image can be changed simply by tweaking its alpha channel. Or color correction, say remapping bright red to some other color, can be done without concern that the alpha channel has made bright red numerically like dark red simply because of transparency.

But with premultiplied colors, the math of compositing images together is simpler and a division can be avoided much of the time.

The key to understanding the distinction is to give up the idea of alpha as transparent colored glass and instead see it as a screen mesh. For example, if alpha is 50%, then imagine a pixel, half of which is covered by the pixel's color and the other half is completely transparent. Specifically, imagine the left half covered and the right half transparent:

Missing image
Premultiplied_alpha_example_1
Image:Premultiplied alpha example 1

The question is whether the RGB values of the pixel should represent the color of the left half, or only the left half's contribution to the whole pixel. The advantages of doing the former (non-premultiplied) were outlined above. To see the advantages of premultiplied colors, consider compositing another pixel on top of our half-red one. The new one is white (1,1,1) and 50% transparent. So since we're using premultiplied colors, our RGBA is (0.5,0.5,0.5,0.5).

Assuming a screendoor transparency model, we don't know where this half pixel is compared to the half pixel we're compositing over. If our new pixel is also on the left side, then we'll cover the underlying pixel altogether. If it's on the right, we'll patch the hole perfectly. Since we don't know, we'll go half-way and turn it 90 degrees, with the bottom half of the pixel opaque white and the top half transparent:

Missing image
Premultiplied_alpha_example_2
Image:Premultiplied alpha example 2

The result is a pixel whose bottom half is white, top-left quarter is red, and top-right quarter is transparent:

Missing image
Premultiplied_alpha_example_3
Image:Premultiplied alpha example 3

The math for this operation is easy when the numbers are premultiplied:

<math>R' = R_F + (1 - A_F)R_B<math>
<math>G' = G_F + (1 - A_F)G_B<math>
<math>B' = B_F + (1 - A_F)B_B<math>
<math>A' = A_F + (1 - A_F)A_B<math>

The result is (0.75,0.5,0.5,0.75), which is the result of having each color's contribution to the pixel weighted by its area.

The math for non-premultiplied colors is more complex:

<math>R' = (R_FA_F + (1 - A_F)R_BA_B) / A'<math>
<math>G' = (G_FA_F + (1 - A_F)G_BA_B) / A'<math>
<math>B' = (B_FA_F + (1 - A_F)B_BA_B) / A'<math>
<math>A' = A_F + (1 - A_F)A_B<math>

The divide is unnecessary if the foreground or the background is opaque, which is a common situation since compositing sequences usually start with a fully-opaque background image and add things to it.

With 8-bit colors, premultiplying might result in losing color precision that will be needed later when dividing out the alpha to do some color correction.

Generally speaking, premultiplication is a better choice when compositing speed is important and other operations are less common, and non-premultiplication is better if compositing speed is not as important as precision and other operations.

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools