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?
How to tell visible color from RGB values
Asked Answered
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]);
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.
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)
Worked like a charm! For anyone looking on, I found my green values were closer to
.6
and the blue values were closer to .9
, so the >.5
test might not always get the right results. –
Elishaelision Not everyone sees colors the same way, or even if they do, assign them the same name. Especially the boundary between green and blue. Try arguing about it if you find someone who thinks something is blue when you think it's green or vice versa ;-) –
Containment
How did you find out those values, Jayjey? –
Digiovanni
© 2022 - 2024 — McMap. All rights reserved.
S
aturation orV
alue) – Guayaquil