在数组中找到与另一种颜色最接近的颜色的最佳算法是什么? [英] What is the best algorithm for finding the closest color in an array to another color?

查看:22
本文介绍了在数组中找到与另一种颜色最接近的颜色的最佳算法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从传感器读取颜色 (RGB).我还有一个已知"颜色列表,每个颜色都与一个字符串名称配对.

I have a color (RGB) being read from a sensor. I also have a list of "known" colors, each paired with a string name.

从该列表中提取最接近颜色的名称的最佳方法是什么(即表现得像人类选择颜色一样)?

What would the best way (ie behave like a human choosing colors) to pull the name of the nearest color out of this list?

我已经尝试过使用 RGB 的最短笛卡尔距离,但这使得灰色更接近绿色而不是黑色或白色.

I've tried a shortest cartesian distance with RGB, but that makes grey closer to green than to black or white.

推荐答案

与其使用 RGB,不如尝试使用 HSL(色相、饱和度、亮度)或 HSV(色相、饱和度和值)颜色模型.然后尝试不同的偏见元素,例如在计算距离时,色调比亮度更重要.

Rather than using RGB, try using an HSL (Hue, Saturation, Lightness) or HSV (Hue, Saturation and Value) color model. Then experiment with different elements of bias, e.g. hue being more important than luminance when you're calculating the distance.

这篇关于在数组中找到与另一种颜色最接近的颜色的最佳算法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆