RGB To HSI
RGB To HSI
B
R
G
,g =
, b=
.
R+G+ B
R+G + B
R+G+ B
0.5 ( r g ) + ( r b )
h = cos
1
( r g ) 2 + ( r b )( g b ) 2
h [0, ] for b g
0.5 ( r g ) + ( r b )
h = 2 cos1
1
( r g )2 + ( r b )( g b ) 2
s = 1 3 min( r , g , b ) ;
h [ , 2 ] for b > g
s [0,1]
i = ( R + G + B ) /(3 255) ;
i [0,1] .
For convenience, h, s and i values are converted in the ranges of [0,360], [0,100], [0, 255], respectively ,
by:
H = h 180 / ;
I = i 255 .
S = s 100 and
s = S / 100 ;
i = I / 255
x = i (1 s )
s cos( h )
y = i 1 +
cos ( / 3 h )
z = 3i ( x + y );
when h < 2 / 3 , b = x ; r = y and g = z.
when 2 / 3 h < 4 / 3 , h = h 2 / 3 , and r = x ; g = y and b = z.
when 4 / 3 h < 2 , h = h 4 / 3 , and g = x ; b = y and r = z.
The result r, g and b are normalized values, which are in the ranges of [0,1], therefore, they should be
multiplied by 255 for displaying.
(100,150, 200)
(0,
0,
255)
(100,
200,150)
B
R
G
= 0.444
= 0.222 , g =
= 0.333 , b =
R+G+ B
R+G+ B
R+G+ B
0.5 ( r g ) + ( r b )
h = 2 cos
= 1.167
1
( r g )2 + ( r b )( g b ) 2
s = 1 3 min( r , g , b ) = 0.333
3. Represent H,S,I values in the ranges of [0,360], [0,100] and [0, 255]:
4.
H = h 180 / = 210
S = s 100 = 33.3
I = ( R + G + B ) / 3 = 150
HSI to RGB Conversion
r = x = i (1 s ) = 0.392
s cos(h)
g = y = i 1 +
= 0.588
cos ( / 3 h )
b = z = 3i ( x + y)
7. To represent R,G,B values in the ranges of [0,255], [0,255] and [0, 255]:
8.
R = 255 r = 100
G = 255 g = 150
B = 255 b = 200