2

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

Community
  • 1
  • 1
Tyler Eich
  • 4,239
  • 3
  • 21
  • 45

1 Answers1

2

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
Tyler Eich
  • 4,239
  • 3
  • 21
  • 45
V. Rubinetti
  • 1,324
  • 13
  • 21