Convert RGB to light frequency

南笙酒味 提交于 2019-12-19 02:55:13

问题


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:


  1. Convert from RGB to XYZ
  2. Convert from XYZ to Yxy
  3. Calculate the dominant wavelength of xy
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!