区分 8 种颜色之一的最准确方法是什么? [英] Which is most accurate way to distinguish one of 8 colors?

查看:74
本文介绍了区分 8 种颜色之一的最准确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下我们如何使用一些基本颜色:

Imagine we how some basic colors:

RED = Color ((196, 2, 51), "RED")
ORANGE = Color ((255, 165, 0), "ORANGE")
YELLOW = Color ((255, 205, 0), "YELLOW")
GREEN = Color ((0, 128, 0), "GREEN")
BLUE = Color ((0, 0, 255), "BLUE")
VIOLET = Color ((127, 0, 255), "VIOLET")
BLACK = Color ((0, 0, 0), "BLACK")
WHITE = Color ((255, 255, 255), "WHITE")

我想要一个函数,它获取一个 3 元组作为参数(如 (206, 17, 38)),并且它应该返回它的颜色.例如,(206, 17, 38) 是红色,(2, 2, 0) 是黑色,(0, 255, 0) 是绿色.从 8 种颜色中选择一种最准确的方法是什么?

I want to have a function, which gets a 3-tuple as a parameter (like (206, 17, 38)), and it should return the color which it is. For instance, (206, 17, 38) is red, and (2, 2, 0) is black, and (0, 255, 0) is green. Which is most accurate way to choose one of 8 colors?

推荐答案

简短回答:在与设备无关的色彩空间中使用欧几里得距离(来源:色差 维基百科文章).由于 RGB 与设备相关,因此您应该首先将颜色映射到与设备无关的颜色空间之一.

Short answer: use the Euclidean distance in a device independent color space (source: Color difference article in Wikipedia). Since RGB is device-dependent, you should first map your colors to one of the device-independent color spaces.

我建议将 RGB 转换为 Lab*.再次引用维基百科:

I suggest to convert RGB to Lab*. To quote Wikipedia again:

与 RGB 和 CMYK 颜色模型不同,Lab 颜色旨在近似人类视觉.

Unlike the RGB and CMYK color models, Lab color is designed to approximate human vision.

这是进行转换的方法.获得 Lab 值后,计算您的颜色与所有参考颜色之间的欧几里德距离并选择最接近的一个.

Here's a recipe to do the conversion. Once you have the L, a, b values, calculate the Euclidean distance between your color and all the reference colors and choose the closest one.

实际上,Google Code 上的 python-colormath Python 模块(在 GPL v3 下)) 能够在许多不同的色彩空间之间进行转换,并且还可以计算色差.

Actually, the python-colormath Python module on Google Code (under GPL v3) is capable of converting between many different color spaces and calculates color differences as well.

这篇关于区分 8 种颜色之一的最准确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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