colorsys
— 在颜色系统之间转换
¶
源代码: Lib/colorsys.py
colorsys
模块定义颜色值的双向转换,在计算机监视器使用的 RGB (红绿蓝) 色彩空间和其它 3 坐标系统的颜色表达之间:YIQ、HLS (色相亮度饱和度) 及 HSV (色相饱和度值)。所有这些色彩空间中的坐标都是浮点值。在 YIQ 空间,Y 坐标在 0 和 1 之间,但 I 和 Q 坐标可以为正 (或负)。在所有其它空间,坐标都在 0 和 1 之间。
另请参阅
可找到色彩空间的更多有关信息在 http://www.poynton.com/ColorFAQ.html and https://www.cambridgeincolour.com/tutorials/color-spaces.htm .
colorsys
模块定义了下列函数:
colorsys.
rgb_to_yiq
(
r
,
g
,
b
)
¶
将颜色从 RGB 坐标转换成 YIQ 坐标。
colorsys.
yiq_to_rgb
(
y
,
i
,
q
)
¶
将颜色从 YIQ 坐标转换成 RGB 坐标。
colorsys.
rgb_to_hls
(
r
,
g
,
b
)
¶
将颜色从 RGB 坐标转换成 HLS 坐标。
colorsys.
hls_to_rgb
(
h
,
l
,
s
)
¶
将颜色从 HLS 坐标转换成 RGB 坐标。
colorsys.
rgb_to_hsv
(
r
,
g
,
b
)
¶
将颜色从 RGB 坐标转换成 HSV 坐标。
colorsys.
hsv_to_rgb
(
h
,
s
,
v
)
¶
将颜色从 HSV 坐标转换成 RGB 坐标。
范例:
>>> import colorsys
>>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
(0.5, 0.5, 0.4)
>>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
(0.2, 0.4, 0.4)