Image Segmentation by Using K-Means Clustering
Image Segmentation by Using K-Means Clustering
using K-Means
Clustering
Language- C++
Platform- GNU/LINUX
Compiler – GNU G++
Libraries-
IM-3.6 - for Digital imaging
NEWMAT11 – Matrix library 1
ORGANIZATION
Defense Research & Development
Organization (DRDO)
20
40
60
80
100
120
20 40 60 80 100 120
4
Digital Image
A digital image is a representation of a two-
dimensional image using ones and zeros
Digital imaging is the art of making digital
images
Each image is compiled of a certain amount of
pixels, which are then mapped onto a grid and
stored in a sequence by a computer. Every pixel
in an image is given a tonal value to determine
its hue or color.
5
PIXELS
7
Image Magnification, Reduction
8
Noise Removal, Mosaic
9
Image Segmentation
(one of the vital steps used in Image processing)
10
Below is the Original data, on
which the K-Means steps will
be implemented
14
13
12
11
10
7
8 10 12 14 16 18 20
March 10, 2004 11
Placing K points as the initial
centroids.
Initial Cluster Centers at Iteration 1
14
13
12
11
10
7
8 10 12 14 16 18 20
12
Assigning each object to the group
that has the closest centroid.
In this step, we calculate the distance of each object (pixel)
with the centroids & on comparing, the pixel with shortest
distance resides in the cluster of that centroid.
Euclidean Distance
. If the two pixels that we are considering have
coordinates (x1,y1) and (x2,y2) , then the Euclidean
distance is given by:
13
we got two clusters & the objects in
that cluster are nearer to it as compare
to that of other cluster
Updated Memberships and Boundary at Iteration 1
14
13
12
Y V a ria b le
11
10
7
8 10 12 14 16 18 20
X Variable
14
At 3rd step, we need to re-calculate k new centroids as
barycenters of the clusters resulting from the previous step
i.e., just take the mean of every cluster that will be new
centroid as-
Updated Cluster Centers at Iteration 2
14
13
12
11
10
7
8 10 12 14 16 18 20
13
12
Y V a ria b le
11
10
7
8 10 12 14 16 18 20
X Variable
16
K-MEANS CLUSTERING
The algorithm is composed of the following steps :
1). Place K points into the space represented by the objects
that are being clustered. These points represent initial
group centroids.
2). Assign each object to the group that has the closest
centroid.
3). When all objects have been assigned, recalculate the
positions of the K centroids.
4). Repeat Steps 2 and 3 until the centroids no longer move.
This produces a separation of the objects into groups from
. which the metric to be minimized can be calculated.
17
RESULTS
IM Info File Name: ./flower.jpg
File Size: 17.50 Kb
Format: JPEG - JPEG File Interchange Format
Image Count: 1
Width: 184
Height: 148
Color Space: RGB
Data Type: byte
Data Size: 79.78 Kb
FileFormat: JPEG
ResolutionUnit: DPI
18
Is Packed: Yes
Is Top Down: Yes
Image Orientation:
Top-down
19
Red Plane
123 54 0 25 78 245 54 76 125 245 23 175 129
254 234 21 54 36 87 23 65 92 145 234 74 190
165 34 26 86 187 165 136 134 176 153 12 9 0
Green Plane
23 0 12 7 34 243 65 1 48 21 76 34 87 27 142 163
134 1 98 0 34 234 176 19 1 231 1175 123 32 95
94 36 37 83 95 28 29 83 73 85 93 56 0 124 234
Blue Plane
43 2 65 3 34 243 65 1 48 21 76 34 87 27 142 163
239 0 83 0 31 232 172 10 19 233 1 75 223 62 75
44 66 57 88 55 88 59 73 43 75 93 46 2 224 134 20
K= 6
k=8
21
Gray images
K=5
K=8
22
MATRIX LIB-NEWMAT11
To construct an m x n matrix, A, (m and n are
integers) use Matrix A(m,n);
SquareMatrix SQ(n);
UpperTriangularMatrix UT(n);
SymmetricMatrix S(n);
DiagonalMatrix D(n);
IdentityMatrix I(n);
A.swap(B);
swap(A,B); 23
CONCLUSION
for smaller values of k the algorithms give good results. For larger
values of k, the segmentation is very coarse, many clusters appear in the
images at discrete places.
24
QUERIES ?
THANK YOU
25