简体   繁体   English

如何从RGB值中分辨出可见颜色

[英]How to tell visible color from RGB values

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. 我正在进行一个图像分析项目,该项目检查大量图像中设定位置的rgb值,并且需要能够知道某个区域是绿色还是蓝色。 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. 最初我以为我可以通过测试rgb中的g>b来做到这一点,但我已经意识到,由于混合了红色,绿色图像中通常会出现比绿色更多的蓝色。 How can I tell- possibly a formula or an algorithm, what a color visibly appears to be based on the rgb? 我怎么知道 - 可能是公式或算法,基于rgb的颜色看起来是什么颜色?

You can convert RGB values to HSB values using the Color classes RGBtoHSB method. 您可以使用ColorRGBtoHSB方法将RGB值转换为HSB值。 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 得到的色调值介于0-1之间,绿色(0,255,0)的色调值为0.33,蓝色(0,0,255)为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]);

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. 由此您可以为色调值“更接近”绿色创建度量标准,例如,任何色调值<0.5都比绿色更绿色。

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) 下面的图像描绘了这个颜色空间中的颜色如何变化,在X轴上有色调(注意,此图片色调在0-360度之间变化,而RGBtoHSB返回值0-1)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM