RGB Colors as a Function of Wavelength

To simulate a realistic looking optical spectra on a computer requires an accurate color representation of the radiation. Each frequency/wavelength must be encoded in terms of red, green and blue color components produced by the phophors on most monitors.

To create a color based on a particular wavelength of light I tried many 'canned' subroutines from journals and books however none of them matched the view I got from a handheld spectroscope. So I adopted the brute force approach by interactively tweaking the palette in a paint program to cook up a spectral color spread. While refining the spectra I realized that the brightest color spread could be achieved only by using fully saturated intermediate colors.

From there it was a simple matter to convert the method into Java code by duplicating the linear interpolation that the paint program performed between the five key color points. Although the results are acceptable, you may wish to smooth out the interpolation a bit to remove some of the slope discontinuities in the linear interpolation.

Publications state that 550 nm light is yellow green or lime green, so the position of the key color points may need a little more tweaking. The green point was placed in the center of the spectra range at 550 nm but you may wish to shift it towards the blue slightly for more realism.

An important consideration in the design of such a subroutine is to perform all intermediate calculations on floating point values to reduce cumulative integer quantization errors. Only at the very last step do I cast to integer color values.

References


Spectra Data Sources