HSV colors are composed of a triple of numbers: hue $\in [0, 360)$ (in degrees), saturation $\in [0, 1]$ and value or brightness $\in [0, 1]$. RGB colors instead are more well-known and are also composed of a triple of numbers all of them in the range $[0, 1]$ or in a byte $[0, 255]$.

I was trying to implement an algorithm that converts HSV colors to the corresponding RGB ones, and I managed to do it based on the following algorithm provided by Wikipedia. (I'm reporting the whole related text).

$C = V \times S$

\begin{align} H^\prime &= \frac{H}{60^\circ} \\ X &= C (1 - |H^\prime \;\bmod 2 - 1|) \end{align}

($R_1$, $G_1$, $B_1$) = \begin{cases} (0, 0, 0) &\mbox{if } H \mbox{ is undefined} \\ (C, X, 0) &\mbox{if } 0 \leq H^\prime < 1 \\ (X, C, 0) &\mbox{if } 1 \leq H^\prime < 2 \\ (0, C, X) &\mbox{if } 2 \leq H^\prime < 3 \\ (0, X, C) &\mbox{if } 3 \leq H^\prime < 4 \\ (X, 0, C) &\mbox{if } 4 \leq H^\prime < 5 \\ (C, 0, X) &\mbox{if } 5 \leq H^\prime < 6 \end{cases}

Finally, we can find $R$, $G$, and $B$ by adding the same amount to each component, to match value

\begin{align} &m = V - C \\ &(R, G, B) = (R_1 + m, G_1 + m, B_1 + m) \end{align}

where $H$ is the hue, $V$ is the value, $S$ is the saturation, $C$ is what Wikipedia calls the chroma and $R, G, B$ are correspondingly the values of red, green and blue.

Before wanting to find a way to convert HSV colors to RGB Colors, I had already a formula to convert RGB colors to HSV, which I wanted to manipulate to obtain a inverse formula, but I didn't manage to do it.

Here's a picture:

enter image description here

I could show you my attempts, but they are not useful.


  • How is the formula (provided by Wikipedia) to convert a HSV to RGB colors derived from the formula in the picture above to convert RGB to HSV colors?

I'm asking this question here because I'm looking for a mathematical manipulation of one formula to arrive at another. I'm also asking this question because I think it could be interesting also for others. If you think this question should be moved to another stackexchange's website, feel free to migrate it or just tell me and I will post it where you indicate me.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.