如何将某些颜色分类到颜色范围?

las*_*s88 6 c# wpf rgb colors

如果我得到浅灰色(例如R = G = B = 200)和暗色(例如R = 46,G = 41,B = 35),我想将它们分类为简单的灰色颜色组(想象一下表).

那么,我如何将颜色组织成颜色组呢?

Mar*_*rot 16

对于颜色的视觉分类,通常更容易将颜色转换为HSL或HSV.要检测灰度,请检查饱和度是否低于某个阈值.要检测任何其他颜色,请检查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";
}
Run Code Online (Sandbox Code Playgroud)

你当然可以使用其他一些部门.

我做了一个简单的JavaScript应用程序来测试它:颜色分类