问题
Is it possible to obtain the light frequency of a colour from a RGB representation? I've found the opposite process [1] but I don't know if it's possible this way.
[1] http://www.fourmilab.ch/documents/specrend/
回答1:
AFAIK, there is no direct answer because multiple wavelengths can combine to give the same color right? So you have the wavelengths that map to pure colors and then their combinations can give many other and the same colors. And there are several combinations that can give the same color. This is because of inteference. So you essentially are asking for a one to many mapping.
To answer your question: There is no fixed formula. The reverse formulas will give you a range. That is the best it can get.
回答2:
Maybe Javascript - Sort rgb values can help you.
But the problem is that the wavelength spectrum looks like
And you can convert RGB to HSL, but HSL spectrum looks like
Then, there are problems because wavelength spectrum doesn't have all colors, such as pink.
I guess that's because pink doesn't exist in the nature, it's a combination of the colors of the opposite extremes of light's spectrum. But we have it in RGB.
回答3:
- Convert from RGB to XYZ
- Convert from XYZ to Yxy
- Calculate the dominant wavelength of xy
- Calculate the frequency
回答4:
Looking at the C program that your link refers to, there are color_match values for only 81 different frequencies - these seem to be the labelled frequencies around the edge of Figure 3 in your link. So if you know that your RGB info is for pure light of one frequency, you could work out the RGB info for each of these values and see which it matches most closely - probably after scaling one or the other so that the brightnesses match.
The problem, of course, is that your RGB value might be from a mixture of light at different frequencies. In this case you will get a point that comes from the interior of figure 3 - it won't be close to any of the values around the outside (so at least you will be able to tell that there is a problem) and there will be a large number of possible sets of frequencies that could have produced it - these corresponds to weighted averages of points on the outside of the diagram that average out to produce your point on the interior.
来源:https://stackoverflow.com/questions/12239986/convert-rgb-to-light-frequency