human
Program to Change RGB color model to HSV color model | Python3 program change RGB Color Model to HSV Color Model.
R , G , B values are divided by 255 to change the range from 0. .255 to 0. .1 :.
if cmax and cmax are equal then h = 0.
if cmax equal r then compute h.
if cmax equal g then compute h.
if cmax equal b then compute h.
if cmax equal zero.
compute v.
print ( rgb_to_hsv ( 45 , 215 , 0 ) ) print ( rgb_to_hsv ( 31 , 52 , 29 ) )"
How can the above be solved in Python?
assistant
#Here is code to program to Change RGB color model to HSV color model and the other steps required.
 def rgb_to_hsv ( r , g , b ) :
	r , g , b = r / 255.0 , g / 255.0 , b / 255.0
	if cmax == cmin :
		h = 0
	elif cmax == r :
		h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360
	elif cmax == g :
		h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360
	elif cmax == b :
		h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360
	if cmax == 0 :
		s = 0
	else :
		s = ( diff / cmax ) * 100
	v = cmax * 100
	return h , s , v
print ( rgb_to_hsv ( 129 , 88 , 47 ) )