How to tell visible color from RGB values

前端 未结 1 905
野性不改
野性不改 2021-01-19 00:37

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. Or

相关标签:
1条回答
  • 2021-01-19 01:33

    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)

    enter image description here

    0 讨论(0)
提交回复
热议问题