Archived

This topic is now archived and is closed to further replies.

Finding closest color match in palette

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically, what I''m trying to do is that I have a 24-bit color value, and I need to find the color in my 256-entry palette that is the closest match. Now, I just sum up the differences between the real color and the palette color for each color channel, and choose the color for which this value is smallest. It works ok, but can look a bit strange sometimes. Does anyone know any good algorithm for this? /John

Share this post


Link to post
Share on other sites
The usage of a distance algorithm (using the R,G,B values as X,Y,Z values) gives pretty good results and is *fast* (just don''t bother with the sqrt). The reason you are getting funny colors is probably because there is not a close enough match in your palette (256 is not going to look like 24 or even 16bit). If you want an alternative look up the LAB color system, it was designed to provide a linear distance between colors according to human perception (using the L,A,B values as X,Y,Z values). The biggest downside is the math to convert to it is really slow and personnally I find it doesn''t work as well on really dark shades.

Share this post


Link to post
Share on other sites