将RGB像素转换为波长 [英] convert RGB pixel to wavelength

查看:1848
本文介绍了将RGB像素转换为波长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定从光源(光谱仪)发出的光谱. 为此,我需要将每个像素转换为一个波长.

I need to identify a spectrum emitted from a light source (spectrometer). To do that, I need to convert each pixel to a wavelength.

为克服RGB值不具有单个值的问题,我将使用棱镜,以便获得光学晶格.这样,我正在接收频谱的部署,并且频谱的差异仅沿X轴.

To overcome the problem that the RGB values do not have a single value, I will use a prism so that I will get an optical lattice. This way, I'm receiving a deployment of the spectrum, and the difference in the spectrum is only along the X axis.

我的问题是,如何将像素转换为波长,并接收强度随波长变化的图.

My question is, how do I convert the pixels to wavelengths and receive a plot of intensity as a function of wavelength.

推荐答案

  1. 您必须从x位置获得wavelength

  1. You have to get wavelength from x position

您不能根据颜色计算波长,因为两者并不相同.因此,首先您应该使用已知波长校准光谱仪.通过该推断函数:

You can not compute wavelength from color as the two are not the same thing. So first you should calibrate your spectroscope with known wavelengths. From that infer function:

wavelength = f(x)

通过 LUT 和插值,或通过近似多项式.有关更多信息,请参见:

either by LUT and interpolation, or by approximation polynomial. For more info see:

  • Piecewise cubic interpolation
  • Reverse complex 2D lookup table although you need just 1D case

您可以将太阳光用作参考,并根据已知的光谱(Fraunhofer)线进行校准.这里首先是我在Google上找到的示例:

You can use Sun light as a reference and calibrate based on the known spectral (Fraunhofer) lines. Here first example I found on google:

因此,请在此处拍摄/绘制我拍摄的阳光:

So take/plot a sunlight shot here mine:

交叉匹配 Fraunhofer线(较深的线,请注意可能会超出指数的图像拧紧东西,强度也为R+G+B而不加重量,我们不希望像转换那样的人类感知),并在图像中创建一个已知波长x位置的表格.从中插值您的wavelength = f(x).

cross match the Fraunhofer lines (the darker lines, beware of over exponated images they can screw things up, also the Intensity is R+G+B without weight we do not want human perception like conversion) and make a table of Known wavelengths x positions in your image. From that interpolate your wavelength = f(x).

正如您所看到的,我对太阳光谱的拍摄或多或少与参考光谱匹配(差异是由于光栅材料,拜耳滤镜,相机特性,云层和大气等引起的).但是,如何通过局部最小值不容易检测出Fraunhofer线,因此,也许有些用户辅助GUI样式将是一个更好的主意.

As you can see my shot of Sun's spectra more or less matches the reference one (discrepances are due to grating material, bayer filter, camera properties, clouds and atmosphere,etc...). How ever the Fraunhofer lines are not easily detectable by local minima so may be some user assistance GUI style will be a better idea to start with.

但是请注意,WEB上的大多数光谱图像都是错误的,非线性的或移位的!! 因此,请确保我是根据线性光谱数据创建的参考光谱

But beware that most spectra images on the WEB is wrong or nonlinear or shifted !!! So to be sure I created a reference spectra from linearized spectral data like this and here the result 400-700 [nm]:

这是情节:

灰线是400-700 nm的网格,步长为10 nm.

the gray lines are grid from 400-700 nm with 10 nm step.

这是您的设置的外观:

这是我的分光镜拍摄的图像(在LCD的白色区域看):

Here is image from mine spectro-scope (looking at White area on my LCD):

我使用的是DVD制的光栅,因此是圆弧形的.现在,如果您的相机相对于棱镜处于固定位置,那么对于选定的水平线,像素的x位置直接对应于特定波长.

I am using grating grid made from DVD hence the circular arc shapes. Now if your camera is in fixed position relative to your prism then for selected horizontal line the x position of pixel directly corresponds to a specific wavelength.

如果看不到任何Fraunhofer线,则说明棱镜/光栅之前缺少光圈.我通常使用2张剃须刀,它们之间的距离由薄纸设置的0.1 mm间隔.如果您的图像不清晰,则需要在相机/传感器之前添加一个或多个镜头,或者增加对外界光线的遮挡.

If you do not see any Fraunhofer lines then you are missing aperture before the prism/grating. I usually use 2 razor blades distanced by 0.1 mm set by thin paper. If your image is out of focus you need to add lens(es) before your camera/sensor and or add more shielding from outside light.

正如我之前提到的那样,您无法从颜色中获得波长,因为存在输入光谱的无限"组合,从而产生了相同的RGB响应.例如采取白色...它可以由3个或更多不同的波长甚至连续的白噪声组成.因此,从RGB中您无法确定它是哪一个...如果同时添加x位置与棱镜/光栅的组合,则可以得到波长,但是它将变得更加复杂且精度不高,因此直接从位置...

As I mentioned before You cannot get wavelength from color because there is "infinite" combinations of input spectra creating the same RGB response. For example take white color ... it can be composed form 3 or more distinct wavelengths or even continuous white noise. So from RGB you can not tell which one it is... If you add also the x positon with combination of prism/grating then you can get the wavelength but it would be much more complicated and less precise then direct conversion from just x position...

从RGB计算强度

这可能有些棘手,因为您的传感器对于不同的波长可能具有不同的灵敏度.您可以类似于#1 对强度进行归一化.只需拍摄已知强度的光源并近似估计缺失的波长即可.也可以使用Sunlight作为来源

this may be a bit tricky as your sensor may have different sensitivity for different wavelengths. You can normalize intensity similarly to #1. Just take shot of known intensity light source and approximate for the missing wavelengths. Also this can be done with Sunlight as a source

从归一化的颜色中,您只需计算灰度强度即可.

From normalized color you just compute gray-scale intensity and that is it.

要提高准确性,您可以对同一x的所有像素取平均值.

To improve accuracy you can average all the pixels for the same x.

通常也可以通过设计或删除

Also to boost accuracy and sensitivity usually non color sensor is used (mostly linear cameras) either by design or by removing the Bayer filter so it does not mess up the data.

绘制数据

是波长,y轴上的是强度.如果要应用光谱色,可以使用以下方法:

on x axis is the wavelength and on y axis is the intensity. If you want to apply spectral colors you can use this:

当心校准数据可能会随温度而变化...

Beware calibration data may change with temperature ...

这篇关于将RGB像素转换为波长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆