You are on page 1of 12

1

COLOUR IMAGE ANALYSIS





1. Introduction
Humans perceive colour as a combination of three primary colours, namely, red (R), green
(G) and blue (B). This is in keeping with the tristimulus theory of colour. The RGB space is an
orthogonal Cartesian space and is most commonly used in television systems and digital
cameras. However, it is not appropriate to mimic the higher level processes that are involved in
the human visual system for the perception of colour. In this respect, the hue-saturation-value
representation of color is more suitable. A colour image can be represented using several other
colour spaces. In Fig.1 below, the R, G, B images of a colour image are separately shown.

(a) (b)


(c) (d)


Fig.1 (a) Original colour image, (b) red image, (c) green image, (d) blue image.

2
Primary Complement
Red Cyan
Green Magenta
Blue Yellow


(a) (b)
Fig.2 (a) Primary colours and their complements, (b) Tertiary colors added to the primary and
secondary colours.
Red, Green and Blue are the three primary colors that computer monitors use to create all the
possible colours displayed. They are called the light primaries because they are created colours
by mixing light sources of these colors; in this case, glowing phosphors built into the computer
monitor screen. When you are 180 degrees away from a primary (Fig.2), you get the
complement of the primary. Fig.2a shows the three complementary colors added to the wheel of
colours. Each of these complements has an equal amount of the primaries on either side of it and
none of the primary opposite it. These complementary colors are also called either the secondary
colors or the print primary colors. The term print (or pigment) primaries refers to the fact that
these complements to the light primaries are the colored inks used to mix all possible print ink
pigments. This process can continue filling in colors around the wheel. The next level colors, the
tertiary colors, are those colors between the secondary and primary colors (Fig.2b):
The motivations for colour image analysis are several : (i) object segmentation based on the
colour of the objects, (ii) colour image enhancement, (iii) colour image compression, (iv) colour
image editing etc. Here we will deal with colour segmentation.

2. Clustering of Data

Clustering is an important tool in pattern recognition. It tries to partition a given set of multi-
dimensional points (in our case, a set of pixels in a colour image) into several groups or clusters
(in our case, distinct colour patches) such that in some sense there is as much homogeneity as
3
possible within clusters and as much heterogeneity as possible between clusters. There exist
several clustering algorithms in the literature. Below I describe two algorithms, namely, K-means
algorithm and Expectation Maximization (EM) algorithm.


2.1 K-Means Algorithm
The algorithm partitions a set T =
{ }
N
x x x ,..., ,
2 1
of N p-dimensional feature vectors
into K groups, namely T
1
, T
2
,,, T
K
such that = =
=
I U
j i
K
i i
T T T T and
1
for i j. (In
the case of colour segmentation, p=3.) The mean square error (MSE), denoted by e(y
1
, , y
k
), is
defined as
2
1
1

=

K
i T x
i
i
y x
N
where y
i
=

i
T x
i
x
T
1
is the mean vector of x in T
i
. The K-
means algorithm attempts to minimize the value of MSE by suitably finding the partition which
is in fact determined by y
1
, , y
k
. Although the MSE minimization is not guaranteed here, the
K-means algorithm is quite popular and performs well in many situations. The main steps in the
algorithm are given below where is a pre-determined small positive value.
Step 1: Randomly select K points y
1
, y
2
, , y
K
from T such that
j > i t y y
j i
for
some pre-assigned value t > 0.
Step 2: Find
{ } i j y x y x T x T
j i i
= :
.
Step 3: Find z
i
as the mean of the feature vectors in T
i
.
If
stop then ,..., 2 , 1 K i z y
i i
= <
. Else, set y
i
= z
i
for all i and repeat Step 2 and Step 3.

The value of K is provided by the user here. However, in the algorithm that follows, this
value can be automatically determined. (An illustration of K-Means algorithm is given in the
next page).


2.2 E-M Algorithm

Here it is assumed that the data are generated from a mixture of multivariate Gaussian
distributions. Such a mixture is given by the following probability density function :
) (x f = ) , / (
1
j j j j
K
j
p

x
=
, where the density function parameters are
j
p (prior
probabilities),
j
(mean vectors) and
j
(covariance matrices). ) , / (
j j j
x are individual
multivariate Gaussian distributions. Suppose we have observed samples , {
i
x n i ., . . . , 2 , 1 = }
from the above distribution. The task is to estimate the above mentioned parameters on the basis
of these samples. The estimated parameters will lead to clustering of the samples.

The EM (expectation maximization) is used for maximizing the log likelihood L of the
observed samples
i
x n i ., . . . , 2 , 1 = where ) , / ( log
1 1
j j
n
i
K
j
i j j
p L =

= =
x .

4


Fig.3. An illustration of K-Means algorithm.



5
EM algorithm is as follows.

Step 1: Partition the set of samples into K

equal disjoint groups. For each such group,
compute the mean vector
) 0 (
j and covariance matrix .
) 0 (
j Set
K
p j
1
) 0 (
=

for all j.

Step 2:
EStep n i ., . . . , 2 , 1 = and K j ., . . . , 2 , 1 = compute
) , / (
) , / (
) (
) ( ) (
1
) (
) ( ) ( ) (
) (
t
l
t
l
i
K
l
t
l
t
j
t
j
i
t
j
t
ij
p
p
q

x
x

=
=

where
) 1 (
1
=

=
K
j
ij ij
q q
is the probability that
i
x comes from the j-th component.
M-Step Set
) . . . , ,
, ., . . , , ., . . , (
) 1 ( ) 1 (
2
) 1 (
1
) 1 ( ) 1 (
1
) 1 ( ) 1 (
1
) 1 (
+ + +
+ + + + +
=
t
K
t t
t
K
t t
K
t t
p p



where

=
+
=
n
i
t
ij
t
j q
n
p
1
) ( ) 1 (
) (
1
,

=
= +
=
n
i
t
ij
n
i
i
t
ij
t
j
q
q
1
) (
1
) (
) 1 (
) (
) (

=
+

=
n
i
t
ij
T t
j
i
n
i
t
j
i
t
ij
t
j
q
q
1
) (
) ( ) ( ) (
) 1 (
) (
) ( ) ( ) (

x x

The E-Step and M-Step are repeated until the value of L (the log likelihood value defined above)
stabilizes. The output clusters correspond to the K individual multivariate Gaussian distributions.
An observed sample x is assigned to cluster j if the posterior probability of x belonging to
cluster j is larger than the probability of belonging to any other cluster (see E-Step above).
So far we have assumed the value of K to given. However, there are several ways to
automatically find its value. One such way uses Bayesian information criterion (BIC) which is
defined as ) log( ) ( ) , ( 2 ) ( n M N M L K BIC + , where M is a Gaussian mixture model with K
components, ) , ( M L is the log likelihood value, N(M) is the number of independent parameters to
be estimated and n is the number of observations. For different values of K, we consider the
BIC(K) values. The first local minimum among these values indicates the optimum value of K.
Below we give the results obtained by the above EM algorithm in a problem of extracting
texts from colour document images where the feature vectors contain the Red, Green and Blue
values of the pixels in an image. Figs. (a) indicate the original images. Figs. (b) indicate the
segmented images generated by EM algorithm with K=4. Finally Figs. (c) show the extracted
texts parts.
6

(a) (b)

(c)

(a) (b)

(c) (a)

(b) (c)
Fig.4 Segmentation of text parts from colour document images using EM algorithm in RGB
space. K = 4 in all the cases.
7
3. Hue - Saturation - Intensity Space
Let an image have N pixels having RGB values (r
i
,g
i
,b
i
),
N i ,..., 3 , 2 , 1 =
. Let the
corresponding hue, saturation, brightness values be (h
i
, s
i
, v
i
)
N i ,..., 3 , 2 , 1 =
where
h
i
=

= |

\
|

+
= |

\
|

+
= |

\
|

+
MAX
i
b if
MIN MAX
g r
MAX
i
g if
MIN MAX
r b
MAX
i
r if
MIN MAX
b g
60 * 4
60 * 2
60 * 0
i i
i i
i i

s
i = ( ) MAX MIN MAX /
and

v
i
= MAX
where MAX = max(r
i
, g
i
, b
i
), MIN = min(r
i
, g
i
, b
i
).

This colour space really describes just one dimension of colour: hue. Hue is described with the words
we normally think of as describing color: red, purple, blue, etc. Hue is more specifically described by the
dominant wavelength. Hue is also a term which describes a dimension of colour we readily experience
when we look at colour. It will be the first of the three dimensions we use to describe colour.


Fig 5. Hue, Saturation, Value (HSV) Fig.6 A saturation/value slice
colour model of a specific hue in the HSV model
8

(a) Original colour image. (b) Image depicting hue values.



(c) Image showing saturation values. (d) The hue circle.

Fig.7 Decomposing a colour image into Hue and Saturation components.
9
PLAYING WITH HUE, SATURATION & INTENSITY


(a) (c)

(b) (d)
Fig.8 (a) Original image with flowers of 2 hues which are close to each other. (b) Image
showing the frequency of hue of the flower image. (c) For image in (a), hues falling between 230
and 315 are changed by rotating them by 90 in the anti-clockwise direction (saturation and
intensity are unchanged for each pixel). (d) For image in (a), saturation of pixels having hue
lying between 230 and 315 is increased by 50% (hue and intensity are unchanged for each
pixel).

10


(d) (e)


(f) (g)
Fig.8 (contd.) (e) For image in (d), intensity of pixels having hue lying between 70 and 230 is
reduced by 50% (hue and saturation are unchanged for each pixel). (f) For image in (d),
saturation of pixels having hue lying between 70 and 230 is reduced by 70% (hue and intensity
are unchanged for each pixel). (g) For image in (d), intensity of pixels having hue lying between
70 and 230 is reduced by 50% and saturation in the same range by 70% (hue is unchanged for
each pixel).

11
4. Colour Processing in HSV Space

Processing of Hue in HSI space is not straightforward since Hue is circular rather than linear
data. Saturation and intensity are linear data and pose no extra difficulty in processing. K-Means
algorithm described earlier was based on Euclidean distance since RGB values were linear. This
algorithm needs some changes in H-S space as described below.

4.1 K-Means Algorithm in Hue-Saturation Space

It is a 2-dimensional clustering problem in the HS space. Steps are the same as described
earlier. The definitions of distance and mean are different as given below.

The distance between 2 points u=(a, b) and v=(c, d) in this space is defined as
( )
( )
180
360 , min
,
c a c a
d b v u Dist

+ =
Division by 180 is meant for normalization.
The algorithm starts with K points K i v
i
., . . , 2 , 1 , = in the H-S space. The hue-saturation
values u in the image are partitioned as follows:
( ) ( ) { } i l v u v u u : Dist T
l i i
= , Dist , for K i ., . . , 2 , 1 = .
The mean of the partition is done as follows:

( )
( )
|
|

\
|

i
j
j
j
j
i
N
s
h
h
s
i
a ,
cos
sin
1
tan ) ,
*
(
*
j
j


cluster j i .
i
N is the number of points in the
th
i cluster. h
j
, s
j
are hue and saturation values respectively.
*
i
a takes a value between 90
O
and +90
O
.
Let b
i
= a
i
if

>
i
T h
h cos 0
, and b
i
= a
i
+ 180 if

<
i
T h
h cos 0
.
When

=
i
T h
h cos 0 , set b
i
= +90
O


if

>
i
T h
h sin 0

and b
i
= -90
O
if

<
i
T h
h sin 0 .








12

References

R.C. Gonzalez and R.E.. Woods, Digital Image Processing, Pearson Education, 2002.

A.K. Jain, Fundamentals of Digital Image Processing, Prentice Hall, Englewood Cliffs,
NewJersey, 1989.

A. Verikas and K. Malmqvist, Increasing Colour Image Segmentation Accuracy by Means of
Fuzzy Post-Processing, Proc. Of Intl Conf. On Neural Networks, Perth, WA, Australia, 27
Nov.-1 Dec. 1995, Vol. 4, pp. 1713-1718.

G. Wyszecki and W.S. Stiles, Color Science: Concepts and Methods, Quantitative Data and
Formulae, Wiley, New York, NY, 1982.

H. D. Cheng et al, Color image segmentation : advances and prospects, Pattern Recognition,
Vol.34, 2001, pp.2259-2281.

R.W.G. Hunt, Measuring Colour, 2
nd
Ed., Ellis Horwood Ltd. Publ., UK, 1987.

T. Uchiyama and M.A. Arbib, Color Image Segmentation Using Competitive Learning, IEEE
Trans. On Pattern Analysis and Machine Intelligence, Vol.PAMI-16, No.12, pp.1197-1206, Dec.
1994.

M. R. Anderberg, Cluster Analysis for Applications, N.Y. Academic, 1973.

K. Fukunaga, Introduction to Statistical Pattern Recognition, N.Y. cademic Press, 1990.

E. Gose, R. Johnsonbaugh and S. Jost, Pattern Recognition and Image Analysis, Prentice Hall of
India, New Delhi, 1999.

You might also like