Convert RGB to HSV (HSB)
The RGB to HSV converter expresses a color as hue, saturation and value, the model behind color pickers, image-processing scripts and computer-vision filters. RGB mixes three lights; HSV separates which color it is (hue) from how pure it is (saturation) and how bright it is (value), which makes it far easier to select or adjust colors by rule.
The formula
Scale R, G and B to 0–1, then use max, min and d = max − min:
V = max
S = d / max (0 if max = 0)
H = 60 × ((G − B) / d mod 6) if max = R
60 × ((B − R) / d + 2) if max = G
60 × ((R − G) / d + 4) if max = B
0 if d = 0
Worked example: forest green
rgb(34, 139, 34)
R = 0.1333 G = 0.5451 B = 0.1333
max = 0.5451 (G) min = 0.1333 d = 0.4118
V = 0.5451 → 54.5%
S = 0.4118 / 0.5451 → 75.5%
H = 60 × ((0.1333 − 0.1333) / 0.4118 + 2) = 120
→ hsv(120, 75.5%, 54.5%)
Red and blue are equal, so the hue is exactly 120°, pure green. Compare the HSL version of the same color, hsl(120, 60.7%, 33.9%): the hue is identical, but the saturation differs and HSL lightness is unrelated to value.
HSV in code: check the scale
Libraries rarely use the degrees-and-percent notation this tool prints, so rescale before comparing numbers:
| Where | Hue range | S and V range | Forest green |
|---|---|---|---|
| This tool | 0–360 | 0–100% | 120, 75.5%, 54.5% |
Python colorsys | 0–1 | 0–1 | 0.333, 0.755, 0.545 |
| OpenCV, 8-bit images | 0–179 (degrees ÷ 2) | 0–255 | 60, 193, 139 |
OpenCV's halved hue range is a frequent source of bugs in color-thresholding code: a range written for 0–360° silently misses most colors. OpenCV also loads images in BGR channel order by default, so make sure you convert from the right order.
Practical notes
- Hue is rounded to a whole degree, S and V to one decimal place, and fractional RGB input is rounded to integers first.
- Any alpha value in the input is ignored, because HSV has no standard alpha form.
- Pure black is
hsv(0, 0%, 0%); greys have 0% saturation and hue 0. - CSS has no
hsv()function, so use RGB to HSL for stylesheets.
To turn HSV back into screen values, use HSV to RGB or HSV to HEX.
Convert RGB to HSV in Python
colorsys.rgb_to_hsv() from the standard library converts RGB to HSV, on a 0–1 scale for both input and output. Divide each channel by 255 before the call, then multiply the hue by 360 and the other two values by 100 to get degrees and percentages. If you pass 0–255 integers directly, hue and saturation still come out right and only V is wrong (it equals the largest channel), which makes the bug easy to miss.
import colorsys
def rgb_to_hsv(r, g, b):
"""r, g, b as 0-255; returns degrees and percentages."""
h, s, v = colorsys.rgb_to_hsv(r / 255, g / 255, b / 255)
return round(h * 360), round(s * 100, 1), round(v * 100, 1)
print(rgb_to_hsv(255, 99, 71)) # (9, 72.2, 100.0)
print(rgb_to_hsv(70, 130, 180)) # (207, 61.1, 70.6)
print(rgb_to_hsv(46, 139, 87)) # (146, 66.9, 54.5)
# Skip the division and V comes back on the 0-255 scale
print(colorsys.rgb_to_hsv(255, 99, 71))
The rounded results match what this converter shows for the same three colors, so you can paste your own RGB values above to verify a script.