XhCode Online Converter Tools

RGB to HSV

R: G: B:

H: S: V:
#
R
G
B
H
S
B
OK
RGB to HSV

Converting RGB (Red, Green, Blue) values to HSV (Hue, Saturation, Value) involves a series of steps. The RGB values are usually given in the range of 0 to 255, and the resulting HSV values will be in the following ranges:

Hue (H): 0° to 360° (degrees)
Saturation (S): 0 to 1 (or 0% to 100%)
Value (V): 0 to 1 (or 0% to 100%)
Steps to Convert RGB to HSV:
Normalize the RGB values:
Convert the RGB values (ranging from 0 to 255) to a range of 0 to 1 by dividing each value by 255.

r' = R / 255
g' = G / 255
b' = B / 255
Find the Max and Min values:

Max = max(r', g', b')
Min = min(r', g', b')
Delta = Max - Min
Calculate Hue (H): If Delta = 0, then H = 0° (hue is undefined, but it is conventionally set to 0).

Otherwise:

If Max = r', then H = 60 × ((g' - b') / Delta).
If Max = g', then H = 60 × ((b' - r') / Delta + 2).
If Max = b', then H = 60 × ((r' - g') / Delta + 4).
If H < 0, add 360 to H to ensure it's within the range 0° to 360°.

Calculate Saturation (S):

If Max = 0, then S = 0 (the color is a shade of gray).
Otherwise, S = Delta / Max.
Calculate Value (V):

V = Max (this is the brightness or intensity of the color).
Example 1: RGB(255, 87, 51)
Normalize RGB:

r' = 255 / 255 = 1
g' = 87 / 255 ≈ 0.341
b' = 51 / 255 ≈ 0.2
Max, Min, and Delta:

Max = max(1, 0.341, 0.2) = 1
Min = min(1, 0.341, 0.2) = 0.2
Delta = 1 - 0.2 = 0.8
Calculate Hue (H): Since Max = r', we use the formula:

H = 60 × ((g' - b') / Delta)
H = 60 × ((0.341 - 0.2) / 0.8)
H = 60 × (0.141 / 0.8) ≈ 60 × 0.17625 ≈ 10.59°
Calculate Saturation (S):

S = Delta / Max = 0.8 / 1 = 0.8 (or 80%)
Calculate Value (V):

V = Max = 1 (or 100%)
HSV = (10.59°, 80%, 100%)
Example 2: RGB(51, 204, 255)
Normalize RGB:

r' = 51 / 255 ≈ 0.2
g' = 204 / 255 ≈ 0.8
b' = 255 / 255 = 1
Max, Min, and Delta:

Max = max(0.2, 0.8, 1) = 1
Min = min(0.2, 0.8, 1) = 0.2
Delta = 1 - 0.2 = 0.8
Calculate Hue (H): Since Max = b', we use the formula:

H = 60 × ((r' - g') / Delta + 4)
H = 60 × ((0.2 - 0.8) / 0.8 + 4)
H = 60 × (-0.6 / 0.8 + 4)
H = 60 × (-0.75 + 4) = 60 × 3.25 = 195°
Calculate Saturation (S):

S = Delta / Max = 0.8 / 1 = 0.8 (or 80%)
Calculate Value (V):

V = Max = 1 (or 100%)
HSV = (195°, 80%, 100%)
Example 3: RGB(128, 0, 128)
Normalize RGB:

r' = 128 / 255 ≈ 0.502
g' = 0 / 255 = 0
b' = 128 / 255 ≈ 0.502
Max, Min, and Delta:

Max = max(0.502, 0, 0.502) = 0.502
Min = min(0.502, 0, 0.502) = 0
Delta = 0.502 - 0 = 0.502
Calculate Hue (H): Since Max = r':

H = 60 × ((g' - b') / Delta)
H = 60 × ((0 - 0.502) / 0.502)
H = 60 × (-0.502 / 0.502) = 60 × (-1) = -60°
Since H < 0, add 360° to get the hue in the correct range:

H = 360° - 60° = 300°
Calculate Saturation (S):

S = Delta / Max = 0.502 / 0.502 = 1.0 (or 100%)
Calculate Value (V):

V = Max = 0.502
HSV = (300°, 100%, 50%)