2
votes

Explanation

I have a semi-transparent color of unknown value.

I have a sample of this unknown color composited over a black background and another sample over a white background.

How do I find the RGBA value of the unknown color?


Example

Note: RGB values of composites are calculated using formulas from the Wikipedia article on alpha compositing

Composite over black:

rgb(103.5, 32.5, 169.5)

Composite over black

Composite over white:

rgb(167.25, 96, 233.25)

Composite over white

Calculated value of unknown color will be:

rgba(138, 43, 226, 0.75)

Calculated color value


What I've Read

1
Not possible. Look at your values. The one on black ends up lighter than the one on white.stark
Alphas still look way off for the different values.stark
@stark See if my new example is any clearer.Tyler Eich

1 Answers

2
votes

It took some experimentation, but I think I figured it out.

Subtracting any of the color component values between the black and white composite should give you the inverse of the original color's alpha value, eg:

A_original = 1 - ((R_white_composite - R_black_composite) / 255) // in %, 0.0 to 1.0

It should yield the same value whether you use the R, G, or B component. Now that you have the original alpha, finding the new components is as easy as:

R_original = R_black_composite / A_original
G_original = G_black_composite / A_original
B_original = B_black_composite / A_original