Is there a way to identify the colors specified by their hexadecimal codes as shades of a particular color?
I think I found a way, not sure how accurate - but how can I determine if the match matches the color is not good enough?
I need to define color matches for certain colors - a fixed set (red, yellow, orange, blue, green, brown, purple, gray, black, white).
I am currently performing a distance based color approach:
Given the color cfrom the list of fixed colors above (which I set using hex colors, I hope to be in the middle of the range for that color, which I'm not quite sure how to get - right now I'm using a color that looks “good”) and a list of available colors list, I'm trying to find the index from the list with the closest color.
int matchColor(QColor c, QList<QColor> list)
{
int bestIndex = 0;
int distance;
int bestMatch = 0;
int sz = list.size() - 1;
for (int i = 0; i <= sz; ++i)
{
int Rdiff = 255 - qAbs(c.red() - list.at(i).red());
int Gdiff = 255 - qAbs(c.green() - list.at(i).green());
int Bdiff = 255 - qAbs(c.blue() - list.at(i).blue());
distance = Rdiff + Gdiff + Bdiff;
if (distance > bestMatch)
{
bestMatch = distance;
bestIndex = i;
}
}
return bestIndex;
}
The problem is that this correspondence must be strictly observed (for some standards), I must return the shades of a certain color cand fail if I can not.
I'm not 100% sure that the color match is good - although it looks pretty good.
- , ? ( distance 0 765, 765).
, ?
?
. , , , , , ... , .