tags:

views:

176

answers:

5

2 colors are mixed together. If i have the RGB for the resultant color and RGB for one of the colors mixed, then somehow i could calculate the 2nd color?

I will try to explain visually what i am trying to say. Here is a flickr link

http://www.flickr.com/photos/48150615@N08/4407414157

I know that the circle in the middle has an opacity of 20%

Is there any way to know the color value of the circle so that i can deduct that to get the same color value as the background color.

+2  A: 

if i understood the task correctly...

let's do some school math

c is color of initial image, t is color of transparent color, a (for alpha) is transparency, c' is result color.

c' = (1 - a) * t + a * c

you want to find c.

c = (c' - (1 - a) * t) / a

you need to know a, t and c'

Andrey
so lets say then if these are the values :Transparent Color's RGB : 153 153 153 ;Alpha for the transparent color : 20% (normal) ;Result Color's RGB : 159 78 57 ;then what would be the initial color?
AK
calculate it for R, G and B independently: for red: c = (159 - (1 - 0.2)*153) / 0.2 = 183
Andrey
i just applied the same for an image i created in photoshop but its not giving me the right color. Am i doing something wrong?
AK
A: 

Just subtract each component. The components are often stored in hexadecimal format, in which case you will need to convert the numbers to decimal or do hex math.

David Pfeffer
subtract what from what?
nickf
The components from the result minus the components from the first original.
David Pfeffer
can you give me an example? I mean i already tried that but it is not working.
AK
+1  A: 

Firstly it depends how you're going to mix them. That is, you could average the RGB components (this means blue (0,0,255) + yellow (255,255,0) == grey (128,128,128)), or you could work on Hues, Saturation and Value, which often gives a much more "as expected" result.

Anyway, in either case, it's some simple maths:

  • if the way to get the average is C3 = (C1 + C2) / 2
  • then the way to find C2 is C2 = (C3 * 2) - C1
nickf
HSL would also work well
jk
A: 

can anyone give me a solution for the added description?

AK
A: 

CIELAB color space is specially designed for calculating differences between colors, but it might be a overkill in you case. Probably HSV is easy solution for you.

Ross