views:

946

answers:

4

Does anyone know of any formula for converting a light frequency to an RGB value?

+4  A: 

You're talking about converting from wave length to an RGB value.

Look here, will probably answer your question. Thy have an utility for doing this with the source code as well as some explanation.

WaveLengthToRGB

Developer Art
Just reading the same page "There is no unique one-to-one mapping between wavelength and RGB values" - so well you are stuck with a lookup table and heuristics.As a first cut I would look at HSV to RGB conversions since the "Hue" ranges from blue to red. With possibly a slight shift since in RGB domain red+blue = violet and violet has the shortest visible wavelength.
whatnick
isn't it practically the same? freq = c / wavelength
Mauricio Scheffer
@Mauricio Scheffer Yes it is EXACTLY the same.
Joseph Gordon
this Bruton's algorithm is rather aesthetic than realistic
mykhal
+5  A: 

Here's a detailed explanation of the entire conversion process: http://www.fourmilab.ch/documents/specrend/. Source code included!

Stephen Mesa
Yay! Fourmilab!
erickson
And the Fourmilab article makes the important point that some colours are not representable in RGB (bright oranges being a good example) because you cannot "make" arbitrary colours of light by adding three primary colours together, whatever our physics teachers may have told us (well mine did). Too bad, but in practice not usually fatal.
Francis Davey
+2  A: 

I guess I might as well follow up my comment with a formal answer. The best option is to use the HSV colour space - though the hue represents the wavelength it is not a one-to-one comparison.

whatnick
+1  A: 

I did a linear fit of known hue values and frequencies (dropping out red and violet because they extend so far in frequency values that they skew things a bit) and I got a rough conversion equation.

It goes like
frequency (in THz)=474+(3/4)(Hue Angle (in degrees))

I've tried to look around and see if anyone has come up with this equation, but I haven't found anything as of May 2010.

-David Elm

David Elm