gpt4 book ai didi

python - 转换为浮点 sRGB 时,CIELAB 增益饱和

转载 作者:太空宇宙 更新时间:2023-11-03 16:34:06 26 4
gpt4 key购买 nike

我正在使用 python 的 colormatch 将 CIE L*a*b* 转换为 sRGB

输入:

(lab_l=70.0,lab_a=60.0,lab_b=0.0)

输出:

(1.0458503175786145, 0.47183611022803823, 0.682521668019042)

但是,1.045...超出范围 12 个字节。这是预期的行为吗?

最佳答案

L*a*b*的色域比sRGB更宽,所以转换溢出是正常的。

L*a*b* 可以表示每种可感知的颜色,但 0 ≤ r,g,b ≤ 1 范围内的 sRGB 只是一个很小的子集。您的颜色不在此子集之外。

(另请参阅 Boundaries of the visible gamut in a CIE color space )

如果您不喜欢溢出,在色彩数学中您可以使用 clamped_rgb_r, etc properties获取范围 [0.0, 1.0] 内的值,如 explained in the documentation on Color Conversion :

RGB spaces tend to have a smaller gamut than some of the CIE color spaces. When converting to RGB, this can cause some of the coordinates to end up being out of the acceptable range (0.0-1.0 or 1-255, depending on whether your RGB color is upscaled).

Rather than clamp these for you, we leave them as-is. This allows for more accurate conversions back to the CIE color spaces. If you require the clamped (0.0-1.0 or 1-255) values, use the following properties on any RGB color:

  • clamped_rgb_r
  • clamped_rgb_g
  • clamped_rgb_b

示例:

from colormath import color_objects, color_conversions

lab_color = color_objects.LabColor(lab_l=70.0, lab_a=60.0, lab_b=0.0)
rgb_color = color_conversions.convert_color(lab_color, color_objects.sRGBColor)
print(repr(rgb_color))
# sRGBColor(rgb_r=1.045850317578614,rgb_g=0.47183611022803845,rgb_b=0.6825216680190419)
print((rgb_color.clamped_rgb_r, rgb_color.clamped_rgb_g, rgb_color.clamped_rgb_b))
# (1.0, 0.47183611022803845, 0.6825216680190419)

关于python - 转换为浮点 sRGB 时,CIELAB 增益饱和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351401/

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