From spectrum to the eye tri-stimulus
Once, doing “ray-tracing” simulation of light scattering, I wondered how to transform my nice fresh calculated light energy spectrum (light intensity with respect to wavelength) into a real life color sensation. For example, I wanted to show on my monitor the irisation effect of light scattering by particles like drops of water. It looks trivial but if you thing about it and furthermore look around in the web how to do that, it appeared to me that it is not that simple to understand. Let me redraw a bit the way I could do that. The eye has 3 types of sensitive cone cells. Good, that's easy: let's integrate the sensitivity spectrum of each type multiply by my light spectrum and that's it! But not at all... The stimuli are processed by the neurons in a quite complex way. In fact it has to be: the sensitivity spectra of the cells overlap quite a lot , particularly for the medium and large wavelength cones. See the curves in the figure 1 bellow. In fact the neurons has to process differences of stimuli to be able to distinguish the colors. So any intent to reproduce this color processing done by the cones and the neurons must know exactly the way the neurons encode the colors. It seems that it is still an active research and so still not easily applicable, as I know.
Figure 1: curves of sensitivity of the cone cells (source Wikipedia).
So to do that, we have to use the standard tri-stimulus curves of the CIE (Commission Internationale de l'Eclairage). Let's see briefly how these curves has been produced (already long ago: in 1931) and how to use them. For details see official site of CIE or the chapter 2 of this nice book: “Principles of Color Technology, Billmeyer and Saltzman”. Here are the basics ideas: an experiment of color perception of a sample of individuals has been made in order to produce a standard response curve for all the wavelengths of the visible spectrum (figure 2). The color matching experiment consist in dividing a disk in 2 half parts. On half is illuminated by the light we want to test and the other half is illuminated by three well chosen monochromatic light sources (red green and blue, wavelengths: 700, 546 and 436 nm). The experimentalist asks the observer to tell for which proportion of red, green and blue he sees exactly the same color at each half disk. This experiment is done with all the monochromatic light corresponding to the visible spectrum. Sometimes (between green and blue) it is not possible to obtain the matching with the 3 references source. But it can be obtained sending the light red source in addition to the analyzed source. In this case the power of the red light source matching is plotted with a negative value. One matching obtained, the intensity of each of the 3 lights is reported in the 3 curves called rλ, gλ and bλ (figure 3). The 3 primary wavelengths chosen at this time were exactly 435.8nm, 546.1nm and 700nm.
Figure 2: The experiment used to encode the RGB values of all the spectral monochromatic values.
The observer tells when the correct addition of R G and B powers of each reference source matches the analyzed color (here yellow).
Figure 3: plot of the standard curves for RGB reference sources (source Wikipedia).
Note that the red curve has negative values: this when the experimentalist needs to add red light to the analyzed source to get the matching.
Inversely, if you have a spectrum s(λ) and wants to know the 3 numbers (RGB) representing the perception of color, you just have to multiply each intensity corresponding to each wavelength of your spectrum and sum them. The 3 sums are your tri-stimulus. That's it. The wavelength range must be [380nm → 780nm]. If your spectrum has less value, for example as usual: [400nm → 700nm], the norm says that you can just add the values for 400nm and 700nm at the two extremities of your spectrum.
Expressed with formulas:
Well, that's not all. Sorry. The references sources R G and B chosen are not very good since we have negative values for red and they don't integrated the photometric 1924 reference. For that reason, three other references has been chosen, X Y and Z. They fulfill these two requirements. They are not physically doable. These new references leads to 3 new “standard observer color matching curves” called x, y and z (figure 4). These curves allows you to go directly from your spectrum to the X,Y and Z values. You could also calculate R, G and be and use the transformation equations from R,G,B to X,Y,Z (see for example http://www.easyrgb.com/index.php?X=CALC)
Practically, just apply these formulas:
Figure 4: plot of the standard curves for XYZ reference sources
The tabulated values of x, y and z can be found at CIE web site (they charge for it I guess) or in some web sites dedicated to color.