I need an algorithm or function to map each wavelength of visible range of spectrum to its equivalent RGB values. Is there any structural relation between the RGB System and wavelength of a light? like this image: sorry if this was irrelevant :-]
w - wavelength, R, G and B - color components
this one for example:
if w >= 380 and w < 440:
R = -(w - 440.) / (440. - 350.)
G = 0.0
B = 1.0
elif w >= 440 and w < 490:
R = 0.0
G = (w - 440.) / (490. - 440.)
B = 1.0
elif w >= 490 and w < 510:
R = 0.0
G = 1.0
B = -(w - 510.) / (510. - 490.)
elif w >= 510 and w < 580:
R = (w - 510.) / (580. - 510.)
G = 1.0
B = 0.0
elif w >= 580 and w < 645:
R = 1.0
G = -(w - 645.) / (645. - 580.)
B = 0.0
elif w >= 645 and w <= 780:
R = 1.0
G = 0.0
B = 0.0
else:
R = 0.0
G = 0.0
B = 0.0
There is a relationship between frequency and what is known as Hue, but for complicated reasons of perception, monitor gamut, and calibration, the best you can achieve outside of expensive lab equipment is a gross approximation.
See http://en.wikipedia.org/wiki/HSL_and_HSV for the math, and note that you'll have to come up with your best guess for the Hue ⇔ Frequency mapping. I expect this empirical mapping to be anything but linear.
This is most of what color profiles deal with. Basically, for a given device (scanner, camera, monitor, printer, etc.) a color profile tells what actual colors of light will be produced by a specific set of inputs.
Also note that for most real devices, you only deal with a few discrete wavelengths of light, and intermediate colors are produced not by producing that wavelength directly, but by mixing varying amounts of the two neighboring wavelengths that are available. Given that we perceive color in the same way, that's not really a problem, but depending on why you care, it may be worth knowing anyway.
Without a color profile (or equivalent information) you lack the information necessary to map RGB value to colors. An RGB value of pure red will normally map to the reddest color that device is capable of producing/sensing (and likewise, pure blue to the bluest color) -- but that "reddest" or "bluest" can and will vary (widely) based on the device.