colorsys
— Conversions between color systems¶
Código-fonte: Lib/colorsys.py
The colorsys
module defines bidirectional conversions of color values
between colors expressed in the RGB (Red Green Blue) color space used in
computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness
Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color
spaces are floating-point values. In the YIQ space, the Y coordinate is between
0 and 1, but the I and Q coordinates can be positive or negative. In all other
spaces, the coordinates are all between 0 and 1.
Ver também
Mais informações sobre espaços de cores podem ser encontradas em https://poynton.ca/ColorFAQ.html e https://www.cambridgeincolour.com/tutorials/color-spaces.htm.
O módulo colorsys
define as seguintes funções:
- colorsys.rgb_to_yiq(r, g, b)¶
Converte a cor de coordenadas RGB para coordenadas YIQ.
- colorsys.yiq_to_rgb(y, i, q)¶
Converte a cor de coordenadas YIQ para coordenadas RGB.
- colorsys.rgb_to_hls(r, g, b)¶
Converte a cor de coordenadas RGB para coordenadas HLS.
- colorsys.hls_to_rgb(h, l, s)¶
Converte a cor de coordenadas HLS para coordenadas RGB.
- colorsys.rgb_to_hsv(r, g, b)¶
Converte a cor de coordenadas RGB para coordenadas HSV.
- colorsys.hsv_to_rgb(h, s, v)¶
Converte a cor de coordenadas HSV para coordenadas RGB.
Exemplo:
>>> 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)