Does anyone know of any formula for converting a light frequency to an RGB value?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to display an image represented by three matri
- How to get a fixed number of evenly spaced points
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
- Is there an existing solution for these particular
- How to measure complexity of a string?
I guess I might as well follow up my comment with a formal answer. The best option is to use the HSV colour space - though the hue represents the wavelength it is not a one-to-one comparison.
Here's a detailed explanation of the entire conversion process: http://www.fourmilab.ch/documents/specrend/. Source code included!
For lazy guys (like me), here is an implementation in java of the code found in @user151323 's answer (that is, just a simple translation from pascal code found in Spectra Lab Report):
By the way, this works fine for me.
I did a linear fit of known hue values and frequencies (dropping out red and violet because they extend so far in frequency values that they skew things a bit) and I got a rough conversion equation.
It goes like
frequency (in THz)=474+(3/4)(Hue Angle (in degrees))
I've tried to look around and see if anyone has come up with this equation, but I haven't found anything as of May 2010.
You're talking about converting from wave length to an RGB value.
Look here, will probably answer your question. Thy have an utility for doing this with the source code as well as some explanation.
WaveLengthToRGB
Although this is an old question and already gets a handful good answers, when I tried to implement such conversion functionality in my application I was not satisfied with the algorithms already listed here and did my own research, which gave me some good result. So I'm going to post a new answer.
After some researchs I came across this paper, Simple Analytic Approximations to the CIE XYZ Color Matching Functions, and tried to adopt the introduced multi-lobe piecewise Gaussian fit algorithm in my application. The paper only described the functions to convert a wavelength to the corresponding XYZ values, so I implemented a function to convert XYZ to RGB in the sRGB color space and combined them. The result is fantastic and worth sharing:
my code is written in Java 8, but it shouldn't be hard to port it to lower versions of Java and other languages.