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?
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?
Just looking at the numbers you provided:
Where:
This fits the B and G channels of your example.
So, in the general case, it seems to be a simple weighted average between the channel value (either of RGB) and the background color (in your case, white -- 255). Alpha is being used as the weight.
Here's some Python code:
And some output:
Try this for other examples (in particular, non-white backgrounds) -- it's probably that simple. If not, edit your answer with new examples, and I'll have another look.
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:
Rearranging the formula, you obtain:
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.