Computer Science, asked by jskwkks, 6 months ago

Write a Python program to convert RGB color to HSV color.​

Answers

Answered by Anonymous
2

HSV - (hue, saturation, value), also known as HSB (hue, saturation, brightness), is often used by artists because it is often more natural to think about a color in terms of hue and saturation than in terms of additive or subtractive color components. HSV is a transformation of an RGB colorspace, and its components and colorimetry are relative to the RGB colorspace from which it was derived.

Inputs

def rgb_to_hsv(r, g, b):

r, g, b = r/255.0, g/255.0, b/255.0

mx = max(r, g, b)

mn = min(r, g, b)

df = mx-mn

if mx == mn:

h = 0

elif mx == r:

h = (60 * ((g-b)/df) + 360) % 360

elif mx == g: h = (60 * ((b-r)/df) + 120) % 360

elif mx == b: h = (60 * ((r-g)/df) + 240) % 360

if mx == 0: s = 0

else:

s = (df/mx)*100

v = mx*100

return h, s, v

print(rgb_to_hsv(255, 255, 255))

print(rgb_to_hsv(0, 215, 0))

Attachments:
Similar questions