Finding the best color match - and deviation if there are no shades of color

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;
        }
    }

    // if(bestMatch < 600 ? or something ?) return -1;

    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).
, ?

?

. , , , , , ... , .

+4
2

, , HSV, . H- , , 20 30 . S V ; , , .

: RGB HSV HSV RGB 0-255

+6

, Delta E. Delta E Lab, Lab .

DeltaE=sqrt(pow(L1-L2,2)+pow(a1-a2,2)+pow(b1-b2,2))

Lab, L, a b. L - . a b . , a b . - , - .

, Delta E. DeltaE2000, , DeltaE .

, sRGB Lab.

RGB CIE LAB

+4

Source: https://habr.com/ru/post/1649213/


All Articles