blob: 1360c7cc9f1db46eda64511c42853dffba7dfee1 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`colorsys` --- Conversions between color systems
2=====================================================
3
4.. module:: colorsys
5 :synopsis: Conversion functions between RGB and other color systems.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Georg Brandl116aa622007-08-15 14:28:22 +00007.. sectionauthor:: David Ascher <da@python.net>
8
Raymond Hettingera1993682011-01-27 01:20:32 +00009**Source code:** :source:`Lib/colorsys.py`
10
11--------------
Georg Brandl116aa622007-08-15 14:28:22 +000012
13The :mod:`colorsys` module defines bidirectional conversions of color values
14between colors expressed in the RGB (Red Green Blue) color space used in
15computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness
16Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color
17spaces are floating point values. In the YIQ space, the Y coordinate is between
180 and 1, but the I and Q coordinates can be positive or negative. In all other
19spaces, the coordinates are all between 0 and 1.
20
Alexandre Vassalotti6461e102008-05-15 22:09:29 +000021.. seealso::
22
23 More information about color spaces can be found at
Sanyam Khurana338cd832018-01-20 05:55:37 +053024 http://poynton.ca/ColorFAQ.html and
Serhiy Storchaka6dff0202016-05-07 10:49:07 +030025 https://www.cambridgeincolour.com/tutorials/color-spaces.htm.
Georg Brandl116aa622007-08-15 14:28:22 +000026
27The :mod:`colorsys` module defines the following functions:
28
29
30.. function:: rgb_to_yiq(r, g, b)
31
32 Convert the color from RGB coordinates to YIQ coordinates.
33
34
35.. function:: yiq_to_rgb(y, i, q)
36
37 Convert the color from YIQ coordinates to RGB coordinates.
38
39
40.. function:: rgb_to_hls(r, g, b)
41
42 Convert the color from RGB coordinates to HLS coordinates.
43
44
45.. function:: hls_to_rgb(h, l, s)
46
47 Convert the color from HLS coordinates to RGB coordinates.
48
49
50.. function:: rgb_to_hsv(r, g, b)
51
52 Convert the color from RGB coordinates to HSV coordinates.
53
54
55.. function:: hsv_to_rgb(h, s, v)
56
57 Convert the color from HSV coordinates to RGB coordinates.
58
59Example::
60
61 >>> import colorsys
Ezio Melotti40507922013-01-11 09:09:07 +020062 >>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
63 (0.5, 0.5, 0.4)
64 >>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
65 (0.2, 0.4, 0.4)