Register to reply 
Math behind mixing two colors 
Share this thread: 
#1
Aug2508, 05:00 AM

P: n/a

Hi,
I am stuck at the math one needs to do to mix colors. Here is the exact problem statement: I am provided the intensities (a.u.) of all the wavelengths in the visible range (400 to 670 nm). I know the RGB values (between 01) at all the wavelengths. I need to mix all the wavelengths and find out the color I would get. For example: If the intensity at 650nm is 1 and rest are all 0 I would get a shade of red. If I have intensities of 0.5 at 530 nm (green) and 670 nm (red) then I should get yellow. To simplify the above problem: If I am given the intensity and the RGB value (between 0.0 and 1.0) at all 3 channels, for two colors. How do I "mix" them so as to obtain a new color. Remember the math should be able to satisfy all the basic rules like: 1. 1 Red + 1 Red = 2 Red 2. Red + Blue + Green = White 3. The RGB value for the final color should stay between 0 and 1. 4. 0.5 Red + 0.5 Green = 1.0 Yellow BUT 0.99 Red + 0.01 Green NOT= 1.0 Yellow Sorry for the long post. Someone please HELP!! mm 


#2
Aug2508, 07:43 AM

Mentor
P: 12,074

Colors are characterized by their x and y chromaticity coordinates. You can start with the Wikipedia article,
http://en.wikipedia.org/wiki/CIE_1931_color_space A google search on the following: x y chromaticity (or variations on those terms) might turn up more info. 


#3
Aug2508, 09:41 AM

Sci Advisor
HW Helper
P: 4,300

Err, how do I read
Shouldn't 1 red + 1 red be 1 red (allowing all coefficients to range from 0 to 1 separately) or undefined (e.g. only allowing coefficients which sum to 1) 


#4
Aug2708, 05:00 AM

P: n/a

Math behind mixing two colors
On 24 Aug, 21:07, MM <extra.mem...@gmail.com> wrote:
> Hi, > > I am stuck at the math one needs to do to mix colors. Here is the > exact problem statement: > I am provided the intensities (a.u.) of all the wavelengths in the > visible range (400 to 670 nm). I know the RGB values (between 01) at > all the wavelengths. I need to mix all the wavelengths and find out > the color I would get. For example: If the intensity at 650nm is 1 and > rest are all 0 I would get a shade of red. If I have intensities of > 0.5 at 530 nm (green) and 670 nm (red) then I should get yellow. > > To simplify the above problem: > If I am given the intensity and the RGB value (between 0.0 and 1.0) at > all 3 channels, for two colors. How do I "mix" them so as to obtain a > new color. Remember the math should be able to satisfy all the basic > rules like: > 1. 1 Red + 1 Red = 2 Red > 2. Red + Blue + Green = White > 3. The RGB value for the final color should stay between 0 and 1. > 4. 0.5 Red + 0.5 Green = 1.0 Yellow BUT 0.99 Red + 0.01 Green NOT= 1.0 > Yellow > > Sorry for the long post. Someone please HELP!! > > mm What you have to do is to sum up sensitivities at all your wavelengths, and then you will get an apparent color. These cureves are given here. http://en.wikipedia.org/wiki/Color_model The red curve is quite interesting. Blue is in fact a mixure of blue and red as the red curve has 2 humps. It does not therefore work quite as you are suggesting. You need to work out at each wavelength what you need to get the color. You have to solve 3 simultaneous equations in each case.  Ian Parker 


#5
Aug2808, 05:00 AM

P: n/a

MM wrote:
> Hi, > > I am stuck at the math one needs to do to mix colors. Here is the > exact problem statement: > I am provided the intensities (a.u.) of all the wavelengths in the > visible range (400 to 670 nm). I know the RGB values (between 01) at > all the wavelengths. I need to mix all the wavelengths and find out > the color I would get. This is the same problem a color camera has to solve. I think they use 3 filters, one for each of {RGB}. So you just integrate the spectrum weighted by a filter function for each component. Gerard 


#6
Aug2808, 05:00 AM

P: n/a

Just add the corresponding R,G,B values together for all the colours
you want to mix, then divide everything by the highest resulting value. So in mathematical terms for n colours R=R1+R2 +...Rn G=G1+G2 +...Gn B=B1 +B2+...Bn r=R/max(R,G,B) g=G/max(R,G,B) b=B/max(R,G,B) Thomas 


#7
Aug2908, 05:00 AM

P: n/a

On Aug 26, 9:43 am, Ian Parker <ianpark...@gmail.com> wrote:
> On 24 Aug, 21:07, MM <extra.mem...@gmail.com> wrote: > > > > > Hi, > > > I am stuck at the math one needs to do to mix colors. Here is the > > exact problem statement: > > I am provided the intensities (a.u.) of all the wavelengths in the > > visible range (400 to 670 nm). I know the RGB values (between 01) at > > all the wavelengths. I need to mix all the wavelengths and find out > > the color I would get. For example: If the intensity at 650nm is 1 and > > rest are all 0 I would get a shade of red. If I have intensities of > > 0.5 at 530 nm (green) and 670 nm (red) then I should get yellow. > > > To simplify the above problem: > > If I am given the intensity and the RGB value (between 0.0 and 1.0) at > > all 3 channels, for two colors. How do I "mix" them so as to obtain a > > new color. Remember the math should be able to satisfy all the basic > > rules like: > > 1. 1 Red + 1 Red = 2 Red > > 2. Red + Blue + Green = White > > 3. The RGB value for the final color should stay between 0 and 1. > > 4. 0.5 Red + 0.5 Green = 1.0 Yellow BUT 0.99 Red + 0.01 Green NOT= 1.0 > > Yellow > > > Sorry for the long post. Someone please HELP!! > > > mm > > What you have to do is to sum up sensitivities at all your > wavelengths, and then you will get an apparent color. These cureves > are given here. > > http://en.wikipedia.org/wiki/Color_model > > The red curve is quite interesting. Blue is in fact a mixure of blue > and red as the red curve has 2 humps. It does not therefore work quite > as you are suggesting. You need to work out at each wavelength what > you need to get the color. You have to solve 3 simultaneous equations > in each case. > >  Ian Parker Hi Ian, Thanks for our reply. The wikipedia link that you referred me to describes how one can express colors in numbers. There are different ways (RGB, CIE, HSV etc) and I think one can convert from one format to another as well. If I sum up all the intensities then I will have the total intensity but of what color? For example: if if the intensity of blue light if 1 (a.u.) and that of red is 0.05 then then the total intensity is 1.05 but I dont have anything that tells me that it should have a bluish shade. Is the weighted average of RGB values the right way to go? mm 


#8
Aug2908, 05:00 AM

P: n/a

On Aug 26, 2:43 pm, Ian Parker <ianpark...@gmail.com> wrote:
> On 24 Aug, 21:07, MM <extra.mem...@gmail.com> wrote: > > > > > Hi, > > > I am stuck at the math one needs to do to mix colors. Here is the > > exact problem statement: > > I am provided the intensities (a.u.) of all the wavelengths in the > > visible range (400 to 670 nm). I know the RGB values (between 01) at > > all the wavelengths. I need to mix all the wavelengths and find out > > the color I would get. For example: If the intensity at 650nm is 1 and > > rest are all 0 I would get a shade of red. If I have intensities of > > 0.5 at 530 nm (green) and 670 nm (red) then I should get yellow. > > > To simplify the above problem: > > If I am given the intensity and the RGB value (between 0.0 and 1.0) at > > all 3 channels, for two colors. How do I "mix" them so as to obtain a > > new color. Remember the math should be able to satisfy all the basic > > rules like: > > 1. 1 Red + 1 Red = 2 Red > > 2. Red + Blue + Green = White > > 3. The RGB value for the final color should stay between 0 and 1. > > 4. 0.5 Red + 0.5 Green = 1.0 Yellow BUT 0.99 Red + 0.01 Green NOT= 1.0 > > Yellow > > > Sorry for the long post. Someone please HELP!! > > > mm > > What you have to do is to sum up sensitivities at all your > wavelengths, and then you will get an apparent color. These cureves > are given here. > > http://en.wikipedia.org/wiki/Color_model Since the OP is given the RGB values for each wavelength, I don't think he needs to worry too much about sensitivities, as these are implied in the RGB values. Furthermore, since there are more colours than names for them, it seems to me that he would be better employed by displaying the resultant colours on a computer screen. This can be done very easily in HTML using COLOR=(hash) xxyyzz where xx,yy and zz are the RGB intensities translated into hexadecimal. Bear in mind though that different screens display colour slightly differently, as do different printers, unless carefully calibrated using specialised equipment. 


#9
Aug2908, 05:00 AM

P: n/a

Hmm while this thread is interesting, it is not physics. The OP could
get best help in some biology forums, or even in art forums. It is about the perception of retinal cells. On 26 ago, 15:43, Ian Parker <ianpark...@gmail.com> wrote: > On 24 Aug, 21:07, MM <extra.mem...@gmail.com> wrote: > > > > > Hi, > > > I am stuck at the math one needs to do to mix colors. Here is the > > exact problem statement: > > I am provided the intensities (a.u.) of all the wavelengths in the > > visible range (400 to 670 nm). I know the RGB values (between 01) at > > all the wavelengths. I need to mix all the wavelengths and find out > > the color I would get. For example: If the intensity at 650nm is 1 and > > rest are all 0 I would get a shade of red. If I have intensities of > > 0.5 at 530 nm (green) and 670 nm (red) then I should get yellow. > > > To simplify the above problem: > > If I am given the intensity and the RGB value (between 0.0 and 1.0) at > > all 3 channels, for two colors. How do I "mix" them so as to obtain a > > new color. Remember the math should be able to satisfy all the basic > > rules like: > > 1. 1 Red + 1 Red = 2 Red > > 2. Red + Blue + Green = White > > 3. The RGB value for the final color should stay between 0 and 1. > > 4. 0.5 Red + 0.5 Green = 1.0 Yellow BUT 0.99 Red + 0.01 Green NOT= 1.0 > > Yellow > > > Sorry for the long post. Someone please HELP!! > > > mm > > What you have to do is to sum up sensitivities at all your > wavelengths, and then you will get an apparent color. These cureves > are given here. > > http://en.wikipedia.org/wiki/Color_model > > The red curve is quite interesting. Blue is in fact a mixure of blue > and red as the red curve has 2 humps. It does not therefore work quite > as you are suggesting. You need to work out at each wavelength what > you need to get the color. You have to solve 3 simultaneous equations > in each case. > >  Ian Parker 


#10
Aug2908, 05:06 AM

P: n/a

MM wrote:
> The wikipedia link that you referred me to > describes how one can express colors in numbers. There are different > ways (RGB, CIE, HSV etc) and I think one can convert from one format > to another as well. If I sum up all the intensities then I will have > the total intensity but of what color? For example: if if the > intensity of blue light if 1 (a.u.) and that of red is 0.05 then then > the total intensity is 1.05 but I dont have anything that tells me > that it should have a bluish shade. Is the weighted average of RGB > values the right way to go? It's considerably more complicated than that, as people's retina pigments vary (e.g. color blindness). For instance, IIRC most people's "red" pigment has a secondary peak in the blue. The brain is HEAVILY involved, and not all 3 colors are required for you to see a color image  the brain's image processing will infer colors that are not actually present. I remember a striking demonstration at a colloquium by Dr. Land. He projected a redandwhite and a blackandwhite image of the same scene next to each other. He then carefully merged them by aiming the projectors, and when the alignment was correct the image suddenly "jumped" into full color. The best way to get a basic understanding is to play with a color wheel  on most computers selecting colors has an option to use such a wheel. Certainly my Mac does. Or you can use RGB sliders and see the resulting color, or CMYK sliders. But, of course, this will all be dependent on the responses of YOUR eyes, and the pigments of YOUR monitor, and the color processing of YOUR computer; other peoples' perceptions and equipment will vary. I believe forums about digital photography discuss this in detail. Tom Roberts 


Register to reply 
Related Discussions  
Mixing colors  Classical Physics  3  
Mixing Colors..  Introductory Physics Homework  9  
Seeing colors  General Physics  2  
Physical parameters define colors like the pigment primaries  Classical Physics  12  
Name colors  Forum Feedback & Announcements  3 