1

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.

AK.
  • 33
  • 2
  • 5
  • See also: http://stackoverflow.com/questions/2049230/convert-rgba-color-to-rgb – amit kumar Mar 04 '10 at 17:55
  • What are you talking about? JPEGs don't do transparency. Given just a pixel in a JPEG, there's no way to go back and tell how it was composed. – nobody Mar 04 '10 at 18:07
  • Thats true. However if i can see the image behind the transparent then there has to be some kind of a way i can get the original color. – AK. Mar 05 '10 at 03:29
  • We can't help you until you figure out how the colors are "mixed". Or maybe we can help you to figure out how the colors are "mixed", but then you'll have to give much more information, and a couple of examples. – AVB Mar 05 '10 at 04:05
  • ok i have added a description – AK. Mar 05 '10 at 05:31

4 Answers4

3

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
  • 59,039
  • 12
  • 119
  • 163
  • 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. Mar 04 '10 at 18:36
  • calculate it for R, G and B independently: for red: c = (159 - (1 - 0.2)*153) / 0.2 = 183 – Andrey Mar 04 '10 at 18:41
  • 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. Mar 04 '10 at 19:12
3

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
  • 537,072
  • 198
  • 649
  • 721
1

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
  • 2,079
  • 2
  • 22
  • 26
0

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
  • 38,869
  • 30
  • 127
  • 202