If I get a lightgray color(for example R=G=B=200) and a dark one(for example R=46,G=41,B=35), I'd like to classify both of them to the simple gray color group(imagine a table).
So, how can I organize the colors to color groups?
For visual classification of colors, it is often easier to convert the color to HSL or HSV first. To detect grays, you check if the Saturation is below some threshold. To detect any other color, you check the Hue.
public string Classify(Color c)
{
float hue = c.GetHue();
float sat = c.GetSaturation();
float lgt = c.GetLightness();
if (lgt < 0.2) return "Blacks";
if (lgt > 0.8) return "Whites";
if (sat < 0.25) return "Grays";
if (hue < 30) return "Reds";
if (hue < 90) return "Yellows";
if (hue < 150) return "Greens";
if (hue < 210) return "Cyans";
if (hue < 270) return "Blues";
if (hue < 330) return "Magentas";
return "Reds";
}
You could of course use some other divisions.
I made a simple JavaScript application to test this: Color classification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With