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?
Method 1
This is bit cleaned up and tested C++11 version of @haochen-xie. I also added a function that converts value 0 to 1 to a wavelength in visible spectrum that is usable with this method. You can just put below in one header file and use it without any dependencies. This version will be maintained here.
The plot of colors from 375nm to 725nm looks like below:
One issue with this method is the fact that it works only between 400-700nm and outside of that it sharply falls down to black. Another issue is narrower blue.
For comparison, below is the colors from Vision FAQ at maxmax.com:
I used this to visualize depth map where each pixel represents depth value in meters and this looks like below:
Method 2
This is implemented as part of bitmap_image single file header-only library by Aeash Partow:
Plot of wavelength from 375-725nm looks like below:
So this is more usable in 400-725nm. When I visualize same depth map as in method 1, I get below. There is an obvious issue of those black lines which I think indicates minor bug in this code which I haven't looked more deeply. Also violets are bit narrower in this method which causes less contrast for far away objects.
General idea:
Steps 1 and 2 may vary.
There are several color matching functions, available as tables or as analytic approximations (suggested by @Tarc and @Haochen Xie). Tables are best if you need a smooth preсise result.
There is no single RGB color space. Multiple transformation matrices and different kinds of gamma correction may be used.
Below is the C# code I came up with recently. It uses linear interpolation over the "CIE 1964 standard observer" table and sRGB matrix + gamma correction.
Result for the 400-700 nm range: