0% found this document useful (0 votes)
39 views

Image Segmentation by Using K-Means Clustering

The document discusses image segmentation using k-means clustering in C++. It begins with an introduction to image segmentation and k-means clustering. It then shows the k-means clustering algorithm applied to sample image data in 4 steps: initializing centroids, assigning pixels to clusters, recalculating centroids, and repeating until convergence. Results are presented showing segmentation of images with different values of k. Libraries used include IM-3.6 for imaging and NEWMAT11 for matrices. The conclusion notes that smaller k values work best with less coarse segmentation and the time complexity of the algorithm.

Uploaded by

Mohit Goel
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Image Segmentation by Using K-Means Clustering

The document discusses image segmentation using k-means clustering in C++. It begins with an introduction to image segmentation and k-means clustering. It then shows the k-means clustering algorithm applied to sample image data in 4 steps: initializing centroids, assigning pixels to clusters, recalculating centroids, and repeating until convergence. Results are presented showing segmentation of images with different values of k. Libraries used include IM-3.6 for imaging and NEWMAT11 for matrices. The conclusion notes that smaller k values work best with less coarse segmentation and the time complexity of the algorithm.

Uploaded by

Mohit Goel
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Image Segmentation by

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)

DRDO has a network of 52 laboratories


eg.
SAG, LASTEC, DTRL
Defense Terrain Research Laboratory 2
CONTENTS
 Introduction
 Image
 Image Processing
 Image Segmentation
 K-Means Clustering
 Results
 Libraries
 Conclusion
 Refrences
3
INTRODUCTION
  The goal is to change the representation of an
image into something that is more meaningful
and easier to analyze i.e. to segment the image

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

Each pixel's color sample has three numerical RGB components


(Red, Green, Blue) to represent the color.
These three RGB components are three 8-bit numbers for each
pixel.
6
Image Processing
Import an Analyze or
Image Manipulate the
Image

 Analog Image Processing Output the result

 Digital Image Processing

7
Image Magnification, Reduction

8
Noise Removal, Mosaic

9
Image Segmentation
(one of the vital steps used in Image processing)

 segmentation refers to the process of partitioning a digital


image into multiple segments (sets of pixels, also known
as superpixels).
 The goal of segmentation is to simplify and/or change the
representation of an image into something that is more
meaningful and easier to analyze.
 Image segmentation is typically used to locate objects
and boundaries (lines, curves, etc.) in images

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

Here, the no. of Clusters in which the pixels of image is to


be divided is 2. hence, k=2

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

we got new centroids after taking the mean of objects of


both clusters.
(Now again the 2nd step is repeated for dividing the objects
in two clusters according to the new centroids) 15
(Below is the final result, convergence has been achieved
i.e., centroids don’t shift any more)

Updated Memberships and Boundary at Iteration 4


14

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.

Further, the computational time complexity of the algorithm is O


(nkl), where n is the total number of objects in the dataset, k is the
required number of clusters we identified and l is the number of
iterations.

24
QUERIES ?

THANK YOU
25

You might also like