如何找到“足够不同”的对象? RGB?

发布于 2024-12-02 12:06:42 字数 117 浏览 2 评论 0原文

如果给你一个 RGB 形式的颜色,是否有办法以编程方式确定它是否与其他 RGB 足够不同。

比如说,我想测试颜色之间是否相差至少 30%,我该怎么做?或者,换句话说,我如何生成与另一种颜色充分不同的颜色?

Provided you are given a color in a form of RGB, is there a way to programmatically determine whether it is sufficiencly different from some other RGB.

Say, i'd like to test whether colors are at least 30% apart from one another, how do i do it? Or, put differently, how can i generate a color that is sufficiently different from another color?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

晌融 2024-12-09 12:06:42

这是一个雷区,因为人类的光学处理非常混乱。但您要问的是色差 - 该页面提供了各种可以使用的不同公式计算代表两种颜色之间“差异”的不同值。

[更新] 这是一个在线计算器,它显然会为您计算这些差异(它很复杂,而且链接不会改变网址,所以很难链接到,但如果你点击它可能会有意义......)

this is a minefield, because human optical processing is horribly messy. but what you're asking about is colour difference - that page gives various different formulae that can be used to calculate different values that represent the "difference" between two colours.

[update] and here's an online calculator that will apparently calculate those differences for you (it's complicated and links don't change urls, so it's hard to link to, but if you click around it might make sense....)

梦醒时光 2024-12-09 12:06:42

这是非常非常主观的。但是,我个人认为最好的机会是使用色相-饱和度-亮度(HSL 或 HSV),并尝试从值的差异中获取值。例如:

value = a*abs(H1-H2)+b*abs(S1-S2)+c*abs(L1-L2);

并尝试通过反复试验,找到区分颜色的最佳 abc 常量与你的人类判断相同的数量。如果您了解线性回归,则可以使用一些具有分配差异的示例颜色,并通过线性回归获得 abc 值。

更合适的公式可能包含 2 次幂的差异,而不是 abs,例如,更重要的是 abc 的值 作为颜色本身的函数而不是常量。

This is very very subjective. However, I personally think your best chance is to use hue-saturation-lightness (HSL, or HSV for that matter), and try to get a value out of the difference in the values. For example something like:

value = a*abs(H1-H2)+b*abs(S1-S2)+c*abs(L1-L2);

and try to, with trial and error, find the best a, b, and c constants that differentiate the colors the same amount as your human judgment does. If you know linear regression, you could have some sample colors with the differences you assign and get the a, b and c values with linear regression.

A more appropriate formula may contain differences in power of 2 instead of abs for example and more importantly values for a, b and c as functions of the colors themselves rather than constants.

层林尽染 2024-12-09 12:06:42

我认为这与几个小时前在另一个问题中遇到的颜色问题相同。在 wikipedia 中了解 HSV(或 HSL)http://en.wikipedia.org/wiki/HSL_and_HSV:当您变换 RGB -> HSV,H值是颜色,S和V是其他特征。

如果想知道颜色之间的距离,只需测量H值即可。如果将其转换为 360 度表示法,30 度足以呈现截然不同的颜色。

如果你想知道 RGB 颜色,那就有点困难了:R、G 和 B 的值可以让你得到一种灰色的“颜色”,而不是一种真正的颜色。

I think it's the same problem you had with colors, some hours ago, in a different question. Read about HSV (or HSL) in wikipediahttp://en.wikipedia.org/wiki/HSL_and_HSV: when you transform RGB -> HSV, the H value is the color, S and V are other characteristics.

If you want to know the distance between colors, just measure the H value. If you transform it to a 360 degrees notation, 30 degrees is enough to give you very different colors.

If you want to know it in RGB colors, it gets a bit harder: the values R, G and B can lead you to a grayish "color", not exactly a color.

被你宠の有点坏 2024-12-09 12:06:42

将 RGB 值视为一个点并使用几何中的距离公式。

distance = ( (R2-R1)^2 + (G2-G1)^2 + (B2-B1)^2 )^.5
distance > minimun value

如果想要相差30%,则取最小值=point_1 * .3到原点的距离,即.3( (R1)^2 + (G1)^2 + (B1)^2 )^。 5

Treat the RGB value as a point and use the distance formula from geometry.

distance = ( (R2-R1)^2 + (G2-G1)^2 + (B2-B1)^2 )^.5
distance > minimun value

In the case of wanting 30% difference, make minimum value = the distance of point_1 * .3 from the origin, ie., .3( (R1)^2 + (G1)^2 + (B1)^2 )^.5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文