Input: RGB
Output: HSV
Steps:
1. Input RGB.
2. Normalize the RGB values to be in the range [0, 1].
r = R/255, g = G/255, b = B/255
3. Find the difference between max and min values.
M = max(r,g,b), m = min(r,g,b). And, the difference Δ = M - m
4. Calculate hue H.
If M = m = 0, then H = 0
If M = r, then compute H = (60 * ((g – b) / Δ) + 360) % 360
If M = g, then compute H = (60 * ((b – r) / Δ) + 120) % 360
If M = b, then compute H = (60 * ((r – g) / Δ) + 240) % 360
5. Calculate saturation S.
If Δ = 0, S = 0; Else, S = Δ/M
6. Calculate value V.
V = max(r,g,b)
7. Output HSV.
r = R/255, g = G/255, b = B/255
3. Find the difference between max and min values.
M = max(r,g,b), m = min(r,g,b). And, the difference Δ = M - m
4. Calculate hue H.
If M = m = 0, then H = 0
If M = r, then compute H = (60 * ((g – b) / Δ) + 360) % 360
If M = g, then compute H = (60 * ((b – r) / Δ) + 120) % 360
If M = b, then compute H = (60 * ((r – g) / Δ) + 240) % 360
5. Calculate saturation S.
If Δ = 0, S = 0; Else, S = Δ/M
6. Calculate value V.
V = max(r,g,b)
7. Output HSV.