colorsys --- 顏色系統間的轉換¶
原始碼:Lib/colorsys.py
Thecolorsys module defines bidirectional conversions of color valuesbetween colors expressed in the RGB (Red Green Blue) color space used incomputer monitors and three other coordinate systems: YIQ, HLS (Hue LightnessSaturation) and HSV (Hue Saturation Value). Coordinates in all of these colorspaces are floating-point values. In the YIQ space, the Y coordinate is between0 and 1, but the I and Q coordinates can be positive or negative. In all otherspaces, the coordinates are all between 0 and 1.
也參考
有關色彩空間的更多資訊請見https://poynton.ca/ColorFAQ.html 和https://www.cambridgeincolour.com/tutorials/color-spaces.htm。
Thecolorsys module defines the following functions:
- 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 座標。
範例:
>>>importcolorsys>>>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)