all Python 3colorsysfunction
colorsys.rgb_to_yiq()
YIQ
Converts a colour from RGB to YIQ — the colour space of analogue NTSC television, where Y is luma and I and Q carry chroma.
Syntax
y, i, q = colorsys.rgb_to_yiq(r, g, b)
Its practical use is the Y component: a weighted luma 0.30·R + 0.59·G + 0.11·B, which converts to greyscale better than the plain mean (r+g+b)/3. I and Q can be negative, unlike HSV and HLS components. The coefficients are dated for modern sRGB work but fine for learning-grade greyscale.
Examples
import colorsys
y, i, q = colorsys.rgb_to_yiq(1, 0, 0)
print(round(y, 3), round(i, 3), round(q, 3)) # → 0.3 0.599 0.213
y, _, _ = colorsys.rgb_to_yiq(0, 1, 0)
print(round(y, 2), round((0 + 1 + 0) / 3, 2)) # → 0.59 0.33 — зелёный ярче среднего
See also
Open in the full glossarydocs.python.orgReport an inaccuracy