Wavelength -> RGB functions

dullard

Elite Member
May 21, 2001
26,130
4,787
126
Suppose I wanted my monitor to display a color that appeared to my eye to be approximately the same as if I saw a light of wavelength X. Are there any formulas that give a good approximation of the RGB colors to use as the color.

[*]I know the monitor displays 3 distinct wavelengths, I know it isn't actually just the one wavelenth I want.
[*]I know monitors vary and thus, even if there was a formula, it would look different on different monitors.
[*]I know the RGB color combination is not unique, as several combinations would have the same wavelength.
[*]I know if you search with Google you get the biggest dicks on the planet complaining about others who asked this question and refusing to help, it is worse than P&N posters here.

With all of that, are there any formulas that would approximately do what I want so that a typical monitor would appear to display approximately the wavelength X when my eyes blend the separate colors together?
 

rivan

Diamond Member
Jul 8, 2003
9,677
3
81
Am I right thinking you're asking for a conversion from a wavelength value to an RGB value?

Edit: if so, it might be easier to convert to either LAB or HSB first, then to RGB. LAB/HSB->RGB tables are pretty established, and I might even be able to find something that can help on that front.

You might be able to get close just with a function to convert (wavelength) to H, set S to 100 and B to whatever's comfortable to view. Then convert that value to RGB.
 

dullard

Elite Member
May 21, 2001
26,130
4,787
126
Originally posted by: rivan
Am I right thinking you're asking for a conversion from a wavelength value to an RGB value?
Yes. For example, suppose I wanted my monitor to fool my eyes into thinking I am seeing 600 nm light. What R, G, and B combination should I use?
 

rivan

Diamond Member
Jul 8, 2003
9,677
3
81
Looks like FoBoT's links should knock it out for you... and clearly I was reinventing the wheel :)
 

dullard

Elite Member
May 21, 2001
26,130
4,787
126
Originally posted by: rivan
Edit: if so, it might be easier to convert to either LAB or HSB first, then to RGB. LAB/HSB->RGB tables are pretty established, and I might even be able to find something that can help on that front.

You might be able to get close just with a function to convert (wavelength) to H, set S to 100 and B to whatever's comfortable to view. Then convert that value to RGB.
Do you have any simple to understand links for something like that?
 

rivan

Diamond Member
Jul 8, 2003
9,677
3
81
Originally posted by: dullard
I've seen that and it was the best I could find. But it seems quite arbitrary and not very close to prism results. I was just curious if there was anything a bit better.

I might be able to help further, if you can give me some additional information about what you're trying to do. That said, you should be able to get color values using the HSB conversion I mentioned above, then adjust S&B to get more "realistic" color, then feed the final result through an HSB->RGB conversion to get a final display color.
 

dullard

Elite Member
May 21, 2001
26,130
4,787
126
Originally posted by: rivan
I might be able to help further, if you can give me some additional information about what you're trying to do. That said, you should be able to get color values using the HSB conversion I mentioned above, then adjust S&B to get more "realistic" color, then feed the final result through an HSB->RGB conversion to get a final display color.
I guess if you could define HSB, define S&B, and if you have any simple links or explainations, then that would be of help.

Basically, I'd like to have a program where you could enter a wavelength, and it would show a close approximation to the color on the screen. The links FoBoT gave above are acceptable, if that is the best I can do (I've already programmed that exact code before I posted this thread). I just was wondering if anyone here knew of anything better.
 

rivan

Diamond Member
Jul 8, 2003
9,677
3
81
This isn't overly technical, and should illustrate why it's perhaps a little more apt to work with while trying to fine-tune your displays.
 

dullard

Elite Member
May 21, 2001
26,130
4,787
126
Originally posted by: rivan
This isn't overly technical, and should illustrate why it's perhaps a little more apt to work with while trying to fine-tune your displays.
Thanks. That was good at describing HSB, and it gave HSB -> RGB functions.

Do you know of anything that gives wavelength -> HSB?
 

Paperdoc

Platinum Member
Aug 17, 2006
2,510
379
126
There's a clue here in the discussions. People talk about RGB (Red / Green / Blue pixels), HSB (Hue / Saturation / Brightness), LAB (Hunterlab L, a, b color co-ordinates), etc. Many of these are good ways to reduce the overall perception of a color to a three-coordinate measurement system. That's because there is much more to color than just wavelength!
One wavelength will give you one pure color only. Next comes Brightness or Intensity. The same pure color can have a huge range of brightness and they'll look different. And if you start mixing two or more pure colors together the eye perceives something quite different, again. So there is no way to translate JUST wavelength into another system - more information is needed.
Now, one could set up a system to assume a constant Brightness and Saturation value and vary only the wavelength. Then you could create a correlation chart of wavelength and the amount of each of three monitor screen pixel colors (R, G, and B values, each ranging from 0 through 255). But don't expect a simple mathematical formula - the eye does not work that way.
 

rivan

Diamond Member
Jul 8, 2003
9,677
3
81
I've not found anything with specific conversion values, but it seems to me you could make yourself a function if properly motivated.

Visible light's roughly 400->750 nm, with apparent colors progressing in a logarithmic fashion. The H value in HSB can use a number of ranges (I've seen 1-100, 0-255, and 1-360) but you should use whichever range suits your HSB->RGB conversion function. Give yourself an offset to start your light range at deep blue (or work backwards from red), and let the values progress through the rest of the linear HSB color wheel.

From there, as I mentioned above, set your saturation value to something that looks 'natural' to you, and brightness to something suitable for viewing (too bright and too dim can both cause eye fatigue very quickly) and do you RGB conversion from the resulting number.