如何从RGB值中识别可见颜色 [英] How to tell visible color from RGB values
问题描述
我正在工作的图像分析项目,检查rgb值在设置的位置在一个主机的图像,并需要能够知道某个区域是绿色还是蓝色。最初我想我可以通过测试 g> b
在rgb,但我已经认识到,通常可以有更多的蓝色比绿色的绿色图像,由于与红色的混合物。
I'm working an image analyzation project that checks the rgb values at set locations in a host of images, and need to be able to know if a certain area is green or blue. Originally I thought I could do this by testing if g>b
in the rgb, but I've come to realize that often there can be more blue than green in a green image, due to the mixture with red. How can I tell- possibly a formula or an algorithm, what a color visibly appears to be based on the rgb?
推荐答案
您可以使用公式或算法来判断颜色是否显示为基于rgb?可以使用 RGB 值转换为 HSB
javase / 1.5.0 / docs / api / java / awt / Color.html#RGBtoHSB%28int,%20int,%20int,%20float []%29rel =nofollow noreferrer>颜色类 RGBtoHSB
方法。所得的色调值在0-1之间,绿色(0,255,0)的色调值为0.33,蓝色(0,0,255)为0.66。
You can convert RGB
values to HSB
values using the Color classes RGBtoHSB
method. The resulting hue value falls between 0-1, with the hue value of green (0,255,0) at 0.33 and blue (0,0,255) at 0.66
float[] hsb = Color.RGBtoHSB(0, 255, 0, null);//green
System.out.println(hsb[0]);
hsb = Color.RGBtoHSB(0, 0, 255, null);//blue
System.out.println(hsb[0]);
从这里可以创建一个色调值更接近绿色的度量,例如任何色调值< 0.5比蓝色更绿。
From this you could create a metric for hue values 'closer' to green, for instance any hue value < 0.5 is more green than blue.
下面是描述颜色在这个颜色空间中如何变化的图像,在X轴上具有色调(注意,在这张图片中,色调从0-360度变化, RGBtoHSB
返回值0-1)
Below is an image depicting how the colors change in this color space, with hue on the X axis (note in this picture hue varies from 0-360 degrees, whereas the RGBtoHSB
returns values 0-1)
这篇关于如何从RGB值中识别可见颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!