如何使用 RGB 获得像素的波长?
我有一个项目可以对像素的颜色进行分类。无论是红色、紫色、橙色还是色轮中的任何颜色。我知道像素的颜色组合超过 1600 万种。但我能够阅读一个网页,上面说我可以使用颜色的波长来完成我的项目。请给我使用 RGB 值计算波长的公式。谢谢!
I have a project that would classify the color of a pixel. Whether it is red,violet, orange or simply any color in the color wheel. I know that there are over 16 million color combination for pixels. But I was able to read a web page that says its possible for me to do my project using the wavelengths of color. Please give me the formula to compute for the wavelength using RGB values. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需将 RGB 转换为 HSV,然后将 HSV 值转换为度数即可,这就是答案:
其中 D 是度数。
考虑到...
紫罗兰色的波长为 380–450 nm,&
蓝色的波长为 450–495 nm,&
绿色的波长为 495–570 nm,&
黄色的波长为 570–590 nm,&
橙色的波长为 590–620 nm,&
红色的波长为 620–750 nm,
那么你只需要检查它是否在这些范围内,然后你就可以对其进行分类。
希望这有帮助!
Just convert the RGB to HSV then get the HSV value to degrees and this is the answer:
where D is the degrees.
Considering...
Violet has a 380–450 nm wavelength, &
Blue has a 450–495 nm wavelength, &
Green has a 495–570 nm wavelength, &
Yellow has a 570–590 nm wavelength, &
Orange has a 590–620 nm wavelength, &
Red has a 620–750 nm wavelength,
then you just need to check if it is in those ranges, then you can classify it.
Hope this helps!
http://en.wikipedia.org/wiki/Visible_spectrum
这是可能的。见上文。灰色背景显然使它更容易。您可能会自己得到类似的东西,甚至可以对其进行改进。但要准确地做到这一点将花费大量资金。您将需要色度专家、校准的显示器和观看环境(因为像素的主波长只是意味着在校准的观看环境中它在校准的显示器上近似的单色波长)。所有这些都需要几千美元。在维基百科上显示的上述链接中完成的工作似乎并不那么准确,但这可能就是您想要的。
http://en.wikipedia.org/wiki/Visible_spectrum
It is possible. See above. Gray background apparently makes it easier. You might get something like that on your own, and even improve on it. But to do it accurately will cost major dollars. U will need a colorimetry expert, a calibrated monitor and viewing environment (since what the dominant wavelength of your pixel is just means what monochromatic wavelength it approximates on your calibrated monitor in your calibrated viewing environment). All this will be a few thousand dollars. The work done at the above link, shown on wikipedia, does not seem that accurate but it is probably what you want.
确定波长有点棘手,正如哥布林提到的,并不总是可行(另一个例子是通过混合等量的红光和蓝光获得的颜色。紫色没有单一波长)。
但如果您只想通过名称识别颜色,那么 HSV 模型将是一个不错的选择。 HSV 是色调(颜色位于色轮周围)、饱和度(有多少颜色,而不是黑/灰/白的阴影)和值(像素的亮或暗程度)。在这种情况下,色调可能正是您想要的。
如果您使用 .NET 语言,那么您很幸运。请参阅 Color.GetHue方法 为您完成所有工作。
否则,请参阅 维基百科上的 HSV 了解更多详细信息。
本质上,如果您将 R、G 和 B 作为范围从 0.0 到 1.0 的浮点数(而不是例如从 0 到 255 的整数),那么:
将 RGB 转换为 HSV 时,您可以将 H' 乘以 60 度,但为了您的目的H'可能没问题。它将是一个范围从 0 到 6(几乎)的浮点数。 0 是红色(6 也是如此)。 1 是黄色,0 到 1 之间的值在红色和黄色之间着色。所以 0.5 就是橙色。重要的里程碑是:
希望有帮助。
Working out wavelength is a bit tricky, and as Goblin mentioned, not always possible (another example is the colour obtained by mixing equal amounts of red and blue light. That purple has no single wavelength).
But if all you want to do is identify the colour by name, then the HSV model would be a good one to use. HSV is Hue (where the colour is around the colour wheel), Saturation (how much colour there is as opposed to being a shade of black/grey/white) and Value (how bright or dark the pixel is). In this case Hue is probably exactly what you want.
If you are using a .NET language, then you're in luck. See the Color.GetHue Method which does all the work for you.
Otherwise, see HSV at Wikipedia for more details.
In essence, if you have R, G and B as floats ranging from 0.0 to 1.0 (instead of ints from 0 to 255 for example), then:
When converting RGB to HSV you then multiply H' by 60 degrees, but for your purposes H' is probably fine. It will be a float ranging from 0 to 6 (almost). 0 is Red (as is 6). 1 is Yellow, with values between 0 and 1 being shaded between Red and Yellow. So 0.5 would be Orange. The important landmarks are:
Hope that helps.
纯色具有波长(任何单色 LED 都具有特定的波长)。
红、绿、蓝各有一个波长范围。然而,当您制作 RGB 颜色时,您将这些波长添加在一起,这不会给您一个新的波长。眼睛无法区分由一种波长组成的黄色与添加红色和绿色的黄色(这正是眼睛的工作原理)。
我建议阅读颜色理论
http://en.wikipedia.org/wiki/RGB_color_model
A pure color has a wavelength (any single color LED will have a specific wavelength).
Red, green and blue each have a range of wavelength. However, when you make an RGB color, you add these wavelengths together, which will NOT give you a new wavelength. The eye can't distinguish a yellow composed of one wavelength from that of adding red and green (just how the eye works).
I'd recommend reading up on color theory
http://en.wikipedia.org/wiki/RGB_color_model
显示器的 RGB 映射到红绿光和蓝光的 3 个独立级别,因此任何一种感知的颜色(大部分)都存在 3 个不同的波长。
但是如果您可以将 RGB 颜色值转换为其等效的 HSL,则在波长范围内,H 部分(色调)是主色如果您准备忽略饱和度(将其视为白度)。
在此基础上,您可以根据 H 值近似颜色的主波长。
红光的波长大约为 630-740nm,紫光的波长大约为 380-450nm。
Well RGB for a monitor maps to 3 independant levels of Red Green and Blue light, so there are (mostly) 3 distinct wavelengths present of any one percieved colour.
BUT If you can convert your RGB colour value to its equivilent HSL, the H part (Hue) is the dominant colour in so far as wavelength goes if you are prepared to ignore the saturation (think of it as whiteness).
Based on that you could approximate the dominante wavelength of a colour based on its H value.
Red light is roughly 630–740nm wavelength, Violet is roughly 380–450nm.