gpt4 book ai didi

c# - 如何降低颜色饱和度?

转载 作者:太空狗 更新时间:2023-10-29 18:16:31 27 4
gpt4 key购买 nike

我可能没有使用正确的颜色术语,但我希望基本上能够缩放类似于所附图片的颜色。我一直在寻找饱和度来做到这一点,因为看起来右边的版本只是左边必须不那么饱和的版本。

enter image description here

我正在尝试这个(我发现的)但它看起来根本不正确:

Public Shared Function GetDesaturatedColor(color As Color) As Color
Const kValue As Double = 0.01R

Dim greyLevel = (color.R * 0.299R) + _
(color.G * 0.587R) + _
(color.B * 0.144R)

Dim r = greyLevel * kValue + (color.R) * (1 - kValue)
Dim g = greyLevel * kValue + (color.G) * (1 - kValue)
Dim b = greyLevel * kValue + (color.B) * (1 - kValue)

' ColorUtils.ToByte converts the double value
' to a byte safely
Return color.FromArgb(255, _
ColorUtils.ToByte(r), _
ColorUtils.ToByte(g), _
ColorUtils.ToByte(b))
End Function

有人知道可以做到这一点的算法吗?

最佳答案

对于那些想要避免将所有内容都转换为 HSL/HSV 并返回的人来说,这相当有效(如果不正确,则取决于人们认为“正确”的去饱和图像是什么):

f = 0.2; // desaturate by 20%
L = 0.3*r + 0.6*g + 0.1*b;
new_r = r + f * (L - r);
new_g = g + f * (L - g);
new_b = b + f * (L - b);

这是使用绿色、红色和蓝色对应于 Luma 的常见假设将 r、g、b 转换为灰度图像的比例分别减小。所以 L 是一个灰度图像,然后 f 只是在输入 RGB 图像和该灰度图像之间进行线性插值。

关于c# - 如何降低颜色饱和度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13328029/

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