Image Processing Reference
In-Depth Information
E
Conversion Between RGB and HSV
In this appendix the conversions from the RGB color representation to the HSV
color representation, and reverse, are derived. That is, we seek a conversion from
[
R,G,B
]
to
[
H,S,V
]
, and one from
[
H,S,V
]
to
[
R,G,B
]
.
E.1
Conversion from RGB to HSV
We recall from Sect. 3.3.2 that HSV is short for hue , saturation and value , and that
value is defined as
V
=
max
{
R,G,B
}
(E.1)
We start by defining a sub-cube of dimension (V,V,V) inside the RGB color
cube, see Fig. E.1 (a). Since V is equal to the maximum RGB value the RGB point
to be converted is located on one of the sides of this sub-cube. Imagine now that we
define a plane perpendicular to the gray-vector and project the corners of the sub-
cube onto this plane. This corresponds to placing your eye at
[
255 , 255 , 255
]
and
looking at
. The result will be the hexagon illustrated in Fig. E.1 (b). Each
corner of the hexagon will point toward one of the corners of the RGB color cube
and are therefore denoted R', Y, G', C, B', and M, corresponding to red, yellow,
green, cyan, blue, and magenta, respectively. 1 In the center of the hexagon we will
have black and white at the same point, denoted W . The RGB point to be converted
is also projected onto the plane and denoted P .
The six corners of the hexagon have the same distance to W . From this follows
that the distances between adjacent corners are equal to each other and to the dis-
tance from a corner to W . Since all lengths in the hexagon are equal we can scale
the hexagon as we please. We choose to scale the hexagon so that all sides have the
length V , which should be interpreted in the following way.
If we assume max
[
0 , 0 , 0
]
{
R,G,B
}=
R we know that the RGB point is located on the
=
side of the sub-cube defined as R
V . This corresponds to one of the two sextants
MWR or RWY . In these two sextants the “position” of P is given as (G, B) ,see
1 The primes are introduced in order to distinguish the color values (R, G, B) from the R, G, and
B corners of the hexagon.

Search WWH ::

Custom Search