Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

What is colorsys.rgb_to_yiq(r, g, b) in Python?

Kainat Asif

The colorsys.rgb_to_yiq(r, g, b) function converts RGB (Red Green Blue) coordinates to YIQ (Luminance (Y) In-phase Quadrature) coordinates.

Declaration

The colorsys module stores the definition of rgb_to_yiq() function. The colorsys module can be imported using the following code:

import colorsys

colorsys.rgb_to_yiq(r, g, b)

r, g, and b can have any value between 0 and 1 inclusive.

Code

The following code snippet demonstrates the use of rgb_to_yiq():

import colorsys

if __name__ == '__main__':
  r = 53
  g = 122
  b = 99

  y, i, q = colorsys.rgb_to_yiq(r, g, b)

  print('RGB:-')
  print('r: ' + str(r) + '\ng: ' + str(g) + '\nb: ' + str(b))
  print('\nYIQ:-')
  print('y: ' + str(y) + '\ni: ' + str(i) + '\nq: ' + str(q))

Explanation

The rgb_to_yiq() function in line 8 converts the r, g, and b values that are created in lines 4-7 to y, i and q values.

RELATED TAGS

CONTRIBUTOR

Kainat Asif
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring