# Visible light spectrum to color space

I need to be able to convert an arbitrary emission spectrum in the visible spectrum range (i.e. for every wavelength between 380 and 780, I have a number between 0 and 1 that represents the "intensity" or dominance of that wavelength), and I need to be able to map any given spectrum into a particular color space (for now I need RGB or CIE-XYZ). Is it possible?

For the spectrum say I have the emission spectrum of a white light, then every wavelength in the spectrum will have an intensity of 1, whereas for a green-bluish light I'd have most of the wavelengths between 500 and 550 with an intensity close to 1, with other wavelengths gradually dropping in intensity. So the first spectrum should be converted to pure white whereas the other one would be converted to a green-bluish color in any color space.

Is there a way to do this?

-
–  Colin K Dec 21 '11 at 0:31
Also, this is a classic optics homework question. –  Colin K Dec 21 '11 at 0:31
This isn't homework and I'm not an optic physics student, I just happened to need to solve this problem and needed some guidance because I didn't understand what I found online via google. Thanks for the link to the question though. –  Thomas Dec 21 '11 at 0:53
White light is not a flat spectrum, it's whatever our eyes perceive as white. White is typically modeled by “standard illuminants”, such as D65 or D50, which mimic average daylight or sunlight spectra. –  Edgar Bonet Dec 21 '11 at 9:04

Human eye has three types of color receptors which respond differently to different parts of the spectrum. See this chart.

One way to tackle your challenge is to basically simulate what the eye does: you take the spectrum as input, calculate how much it would excite each of the three color receptors based on their sensitivity to different parts of the spectrum and then use the three resulting numbers as RGB corresponding to the spectrum.

In order to compute the excitation level, you can integrate the product of the sensitivity SC(λ) of each of the three color receptors with your spectral power distribution P(λ) to obtain the three RGB numbers:

$$R = \int_{0}^{+\infty} S_R(\lambda) P(\lambda) d\lambda$$ $$G = \int_{0}^{+\infty} S_G(\lambda) P(\lambda) d\lambda$$ $$B = \int_{0}^{+\infty} S_B(\lambda) P(\lambda) d\lambda$$

For prototyping you can probably just assume the sensitivity SC(λ) functions to be appropriately scaled and translated Gaussian functions of the wavelength. As you refine your model you should seek better sensitivity functions for each of the three types of color receptors.

-
+1 my thoughts exactly :-) It would be great to find numerical data about the sensitivity functions somewhere. –  David Z Dec 21 '11 at 0:23
There are standard sensitivity functions produced from decades of experimentation. They are maintained by the International Commission on Illumination (CIE). You can find all of that data on the CIE website. –  Colin K Dec 21 '11 at 0:43
Thanks! I used the chart and quickly worked out the mean and sd's for the normal distributions of each color component and obtained this result with (RMean = 570, RSD = 70, GMean = 530, GSD = 50, BMean = 440 and BSD = 40): link. It's still missing the purple band on the left and a few other colors but that's because my approximation is pretty bad, I'll be looking at the CIE site to find the sensitivity functions. Thanks! –  Thomas Dec 21 '11 at 0:55