Thursday, March 31, 2011

journal 3/31

Ok, so here is an equation for HSV to RGB. Honestly, the easiest to understand was wikipedia, so that is where I go this.



Given a color with hue H ∈ [0°, 360°), saturation SHSV ∈ [0, 1], and value V ∈ [0, 1], we first find chroma:

C = V \times S_{HSV}\,\!

Then we can find a point (R1, G1, B1) along the bottom three faces of the RGB cube, with the same hue and chroma as our color (using the intermediate value X for the second largest component of this color):

\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}

No comments:

Post a Comment