Jump to content

Finding a distance between 2 colors

Recommended Posts

I am trying to find a certain like color distance or measurement from one color to the next, like Under Hue / Saturation.


How do I find the numbers from this first color lW4Zg5k.png to this second color


Hue: 0            -----> Hue: ?

Sat: 100         -----> Sat: ?

Lightness: 0   -----> Lightness: ?


Other than physically finding it, which I can't seem to, is there a way to just get these such as a finder or something like that of which I am missing?


Sorry if this is very vague, I am just very confused right now haha

Link to comment
Share on other sites

OK, your best bet then is to just use the :ColorPickerTool: Color Picker Tool and press the More>> button in the  :Colors: Color Docker window.

There, you can see the various values of the current color.

If you were writing a program to do the comparison, you'd usually calculate the difference in colors to determine which color of a palette is the nearest color to the one you're working on. In this scenario, you'd usually calculate the Red, Green, and Blue difference and square it (this makes all values positive--no need to then take the square root).


Color FindNearestColor(Color color, Color[] palette)
    int minDistanceSquared = 255 * 255 + 255 * 255 + 255 * 255 + 1;
    byte bestIndex = 0;
    for (byte i = 0; i < palette.Length; i++)
        int Rdiff = color.R - palette[i].R;
        int Gdiff = color.G - palette[i].G;
        int Bdiff = color.B - palette[i].B;
        int distanceSquared = Rdiff * Rdiff + Gdiff * Gdiff + Bdiff * Bdiff;
        if (distanceSquared < minDistanceSquared)
            minDistanceSquared = distanceSquared;
            bestIndex = i;
    return palette[bestIndex];
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...