gpt4 book ai didi

math - 计算 "colorful"颜色的大小

转载 作者:行者123 更新时间:2023-12-02 00:34:44 24 4
gpt4 key购买 nike

我喜欢创建一个介于 0-1 之间的比率来表示颜色的“多彩”程度,我所说的“多彩”是指:

  • 黑色的比率为 0(无光)
  • 白色的比率为 0(无饱和度)
  • 完全饱和/浅色的比率为 1

我尝试将颜色转换为 HSV 颜色空间并计算比率:

ratio = (color.value / 100) * (color.saturation / 100)

这有点作用,但感觉曲线是错误的,例如

HSV(色调=0,饱和度=80,值=80)

enter image description here

仅给出0.64的比率,但看起来非常接近完全饱和/浅色。

也许我需要以某种方式对值创建“缓出”?我考虑过也考虑人类对颜色的感知(使用 LAB 或 YUV 颜色空间),但我认为这里不需要,但我可能是错的。

最佳答案

HSV 的饱和度定义不是您想要的,因为它不能补偿颜色的亮度。

来自the Wikipedia article on Colorfulness :

[Perceived saturation] is the proportion of pure chromatic color in the total color sensation.

Formula for perceived saturation

where Sab is the saturation, L* the lightness and C*ab is the chroma of the color.

此定义使用 CIELAB colorspace 的 L* 和 C*ab 组件。我的猜测是,对于您的应用程序,您可以使用 Lab 色彩空间。那么你的代码将如下所示:

function perceived_saturation(L, a, b)
return 100 * sqrt(a*a + b*b) / sqrt(L*L + a*a + b*b)

对于示例颜色 RGB = (204, 41, 41),当通过路径 RGB → sRGB → Lab 转换颜色时,这会返回约 86% 的感知饱和度。

关于math - 计算 "colorful"颜色的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34621161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com