Image Processing Reference
In-Depth Information
D
Conversion Between RGB and HSI
In this appendix the conversions from the RGB color representation to the HSI
color representation, and reverse, are derived. That is, we seek a conversion from
[
. When deriving the con-
versions we use a particular point, denoted
P
RGB
=
(P
R
,P
G
,P
B
)
. The rgb version
of this point is denoted
P
R,G,B
]
to
[
H,S,I
]
, and one from
[
H,S,I
]
to
[
R,G,B
]
=
(P
r
,P
g
,P
b
)
.
D.1
Conversion from RGB to HSI
We recall from Sect. 3.3.1 that HSI is short for
hue
,
saturation
and
intensity
, and is
defined as in Fig. 3.11. For the actual derivation it is, however, easier to define hue
and saturation in terms of rgb values as opposed to rg values.
In Chap. 3 it was explained that the rgb values span the triangle in Fig.
D.1
.
This triangle is defined by the three corners
R
=
(
1
,
0
,
0
)
,
G
=
(
0
,
1
,
0
)
, and
B
=
(
0
,
0
,
1
)
. The point
W
(
1
/
3
,
1
/
3
,
1
/
3
)
is the colorless point in the center of the
triangle. Saturation is defined as the ratio
=
−−
WP
−−
WP
/
and hue is defined as the
angle,
θ
, between the two vectors:
−−
WR
and
−−
WP
.
If we define the points
Q
(
1
/
3
,
1
/
3
,
0
)
then we have
two equiangular triangles
WPQ
and
WP
T
, see Fig.
D.2
. Following the law of
similar triangles, see Appendix
B
, we can redefine saturation as
=
(
1
/
3
,
1
/
3
,P
b
)
and
T
=
−−
WP
=
−−
WQ
=
−−
WT
−
−
QT
−
−
QT
−−
WP
S
=
=
1
(D.1)
−−
WT
−−
WT
−−
WT
−−
WT
From the definition of
Q
,
T
, and
W
we have
=
1
/
3 and
(
1
/
3
−
QT
=
−
1
/
3
)
2
+
(
1
/
3
−
1
/
3
)
2
+
(
0
−
P
b
)
2
=
P
b
(D.2)
Substituting this into Eq.
D.1
we get
=
−
·
S
1
3
P
b
(D.3)
P
B
Recall that
P
b
=
and notice that
P
B
=
min
{
P
R
,P
G
,P
B
}
when
P
is lo-
P
R
+
P
G
+
P
B
cated in the triangle
WR
G
. From this follows that