In the RGB model, The red, green, and blue components of a color are constrained to fall between zero and some maximum value. When all components are at their maximum amount, white light is produced. If all components have an equal value less than 100%, a gray tone is produced. The colors produced by the RGB model are very naturally arranged in a cube: if the red, green, and blue components of a color are plotted along the x, y, and z axes respectively, then a specific color can be located by its coordinates in a three dimensional space.

This RGB cube is very straightforward, but its geometry does not reveal the “colorfulness” or “darkness” of a color in a natural way. An alternate way to describe colors is with the hue, saturation and value (HSV) model. This model is usually geometrically described as a cone, where colors toward the point of the cone are dark (low value), and colors further out are brighter (higher value). Colors toward the central axis of the cone are grayer (lower saturation) than the colors located towards the outer surface of the cone (higher saturation). (We should mention, however, that saturation does not entirely coincide with human perception of “colorfulness.”) Rotating around the axis of the cone changes the hue of the color. Hue can be thought of as the main descriptor of a color independent of its intensity or grayness.

Convert RGB to HSV
Max = maximum {R,G,B}
Min = minimum {R,G,B}
Value = Max
Saturation = (Max – Min) / Value
If Max = R and G ≥ B:
Hue = 60*(G – B)/(Max – Min)
If Max = R and B > G:
Hue = 300 + 60*(B – G)/(Max – Min)
If Max = G:
Hue = 120 + 60*(B – R)/(Max – Min)
If Max = B:
Hue = 240 + 60*(R – G)/(Max – Min)






