Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
HSL and HSV
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====HSV to RGB==== [[File:HSV-RGB-comparison.svg|alt=|thumb|300x300px|Fig. 24. A graphical representation of RGB coordinates given values for HSV. This equation <math>V(1-S)= V - VS</math> shows origin of marked vertical axis values.]] Given an HSV color with hue {{math|''H'' β [0Β°, 360Β°)}}, saturation {{math|''S''<sub>''V''</sub> β [0, 1]}}, and value {{math|''V'' β [0, 1]}}, we can use the same strategy. First, we find chroma: : <math>C = V \times S_V</math> Then we can, again, find a point {{math|(''R''<sub>1</sub>, ''G''<sub>1</sub>, ''B''<sub>1</sub>)}} 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): : <math>H^\prime = \frac{H}{60^\circ}</math> : <math>X = C \times (1 - |H^\prime \bmod 2 - 1|)</math> : <math> (R_1, G_1, B_1) = \begin{cases} (C, X, 0) &\text{if } 0 \leq H^\prime < 1 \\ (X, C, 0) &\text{if } 1 \leq H^\prime < 2 \\ (0, C, X) &\text{if } 2 \leq H^\prime < 3 \\ (0, X, C) &\text{if } 3 \leq H^\prime < 4 \\ (X, 0, C) &\text{if } 4 \leq H^\prime < 5 \\ (C, 0, X) &\text{if } 5 \leq H^\prime < 6 \end{cases}</math> As before, when <math>H^\prime</math> is an integer, "neighbouring" formulas would yield the same result. Finally, we can find ''R'', ''G'', and ''B'' by adding the same amount to each component, to match value: : <math>m = V - C</math> : <math>(R, G, B) = (R_1 + m, G_1 + m, B_1 + m)</math> ===== HSV to RGB alternative ===== Given a color with hue <math>H \in [0^\circ,360^\circ]</math>, saturation <math>S=S_V \in [0,1]</math>, and value <math>V \in [0,1]</math>, first we define function : : <math>f(n) = V - VS \max(0, \min(k, 4-k, 1))</math> where <math>k,n \in \mathbb R_{\geq 0}</math> and: : <math>k = \left(n+\frac{H}{60^\circ}\right) \bmod 6</math> And output R,G,B values (from <math>[0,1]^3</math>) are: : <math>(R,G,B) = (f(5), f(3), f(1))</math> Above alternative equivalent formulas allow shorter implementation. In above formulas the <math>a\bmod b</math> returns also fractional part of module e.g. the formula <math> 7.4 \bmod 6 = 1.4</math>. The values of <math>k \in \mathbb R \land k \in [0,6)</math>. The base shape : <math>t(n,H) = T(k) = \max(0, \min(k, 4-k, 1))</math> is constructed as follows: <math>t_1 = \min(k,4-k)</math> is "triangle" for which non-negative values starts from k=0, highest point at k=2 and "ends" at k=4, then we change values bigger than one to one by <math>t_2 = \min(t_1,1) = \min(k,4-k,1)</math>, then change negative values to zero by <math>t = \max(t2,0)</math> β and we get (for <math>n=0</math>) something similar to green shape from Fig. 24 (which max value is 1 and min value is 0). The R,G,B functions of {{mvar|H}} use this shape transformed in following way: modulo-shifted on {{mvar|X}} (by {{mvar|n}}) (differently for R,G,B) scaled on {{mvar|Y}} (by <math>-VS</math>) and shifted on {{mvar|Y}} (by {{mvar|V}}). We observe following shape properties(Fig. 24 can help to get intuition about this): : <math>t(n,H) = 1-t(n+3,H)</math> : <math>\min(t(n,H), t(n+2,H), t(n+4,H)) = 0</math> : <math>\max(t(n,H), t(n+2,H), t(n+4,H)) = 1</math>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)