HSV to RGB conversion explained
HSV is the natural model for generating colors in code: sweep the hue for a rainbow, lower the value for a darker variant, lower the saturation for a washed-out one. Screens, image files and most APIs still want red, green and blue, and this HSV to RGB converter does that translation as you type.
The formula this tool uses
Instead of branching on six hue sectors, the converter uses a compact equivalent. With S and V as fractions and H in degrees:
k(n) = (n + H / 60) mod 6
f(n) = V − V × S × max(0, min(k, 4 − k, 1))
R = 255 × f(5) G = 255 × f(3) B = 255 × f(1)
Worked example: hsv(146, 67%, 55%)
Here V × S = 0.55 × 0.67 = 0.3685 and H / 60 = 2.4333.
R: k = 1.4333 → min(1.4333, 2.5667, 1) = 1 → f = 0.55 − 0.3685 = 0.1815 → 46
G: k = 5.4333 → min(5.4333, −1.4333, 1) → max 0 → f = 0.55 = 0.55 → 140
B: k = 3.4333 → min(3.4333, 0.5667, 1) = 0.5667 → f = 0.55 − 0.3685×0.5667 = 0.3412 → 87
hsv(146, 67%, 55%) → rgb(46, 140, 87)
The green channel is the largest because 146° lies in the green-to-cyan part of the wheel, and it equals V × 255 exactly. The smallest channel is V × (1 − S) × 255.
Values from code libraries
Different libraries scale HSV differently, so check the ranges before pasting numbers here:
- Python colorsys uses 0–1 for all three, including hue. Multiply hue by 360 and the others by 100.
- OpenCV 8-bit images store hue as 0–179 (degrees divided by 2) and S and V as 0–255. Double the hue and divide S and V by 2.55.
- Design tools show degrees and percentages, which you can paste directly.
Fractions work too: in hsv(207, 0.61, 0.71) the saturation and value are read as 61% and 71%, giving rgb(71, 131, 181).
Rounding and round trips
Every result is rounded to whole channel values. The example hsv(146, 67%, 55%) was derived from seagreen, rgb(46, 139, 87), but rounding its value to 55% pushes green up to 140. With one decimal, hsv(146, 66.9%, 54.5%) returns rgb(46, 139, 86), closer still.
Converting the other way is handled by RGB to HSV. If you need an alpha channel, use HSV to RGBA, or go straight to a code with HSV to HEX.
Convert HSV to RGB in Python
Python ships this conversion as colorsys.hsv_to_rgb(), which expects hue, saturation and value as fractions between 0 and 1 and returns red, green and blue on the same scale. Divide the hue by 360 and the percentages by 100 first, then multiply each channel by 255 and round. Forgetting to scale is the common mistake, and it is a silent one: the call does not fail, it returns numbers far outside the 0–1 range, as the last line of the example shows.
import colorsys
def hsv_to_rgb(h, s, v):
"""h in degrees (0-360), s and v in percent (0-100)."""
r, g, b = colorsys.hsv_to_rgb(h / 360, s / 100, v / 100)
return round(r * 255), round(g * 255), round(b * 255)
for hsv in [(9, 72, 100), (207, 61, 71), (146, 67, 55)]:
print(hsv, "->", hsv_to_rgb(*hsv))
# Unscaled input does not raise an error, it returns nonsense
print(colorsys.hsv_to_rgb(9, 72, 100))
Enter the same HSV values in the converter above to confirm that the rounded RGB results match.