The colorsys.rgb_to_hsv(r, g, b)
function converts
The colorsys
module stores the definition of the rgb_to_hsv()
function. We can import the colorsys
module using the following code:
import colorsys
colorsys.rgb_to_hsv(r, g, b)
r
, g
, and b
can have any value between 0 and 1 inclusive.
The following code snippet demonstrates the use of rgb_to_hsv()
:
import colorsys if __name__ == '__main__': r = 152 g = 200 b = 40 ## normalizing values to get value between 0 and 1 r = r/255 g = g/255 b = b/255 h, s, v = colorsys.rgb_to_hsv(r, g, b) print('RGB:-') print('r: ' + str(r) + '\ng: ' + str(g) + '\nb: ' + str(b)) print('\nHSV:-') print('h: ' + str(h) + '\ns: ' + str(s) + '\nv: ' + str(v))
RELATED TAGS
CONTRIBUTOR
View all Courses