Search code examples
image-processingtransparencyalphaalphablendingalpha-transparency

Need help understanding Alpha Channels


I have the RGB tuple of a pixel we'll call P.

(255, 0, 0) is the color of P with the alpha channel at 1.0.

With the alpha channel at 0.8, P's color becomes (255, 51, 51).

How can I get the color of the pixel that is influencing P's color?


Solution

  • Let's start from the beginning. A pixel with alpha only makes sense when it is blended with something else. If you have an upper layer U with alpha and a lower layer L that is totally opaque, the equation is:

    P = (alpha * U) + ((1.0 - alpha) * L)
    

    Rearranging the formula, you obtain:

    L = (P - (alpha * U)) / (1.0 - alpha)
    

    Obviously the equation doesn't make sense when the alpha is 1.0, as you'd be dividing by zero.

    Plugging your numbers in reveals that R=255, G=255, and B=255 for the pixel L.

    It is almost universal that the lowest layer in an image will be all white (255,255,255) by convention.