Assignment 3
1. Implement k-means clustering. Do not use the built-in Matlab function kmeans. Submit one file called
KMeans.m (do not submit or modify Demo1.m) by clicking on the link below (do not email):
[Link]
segmentedImage = KMeans(InIm, numberofClusters, clusterCentersIn)
where:
segmentedImage is an image that codes each located cluster with a different intensity value
InIm is the input image, which can have multiple values at each pixel (more details below)
numberofClusters is the number of clusters to find in the image
clusterCentersIn is an optional parameter that specifies the starting centers of the clusters. If this is
the empty list [], random initialization is used.
Hint: When random initialization is used, it is a good idea to run k-means several times (5 is good) with
different random initializations and keep the best (in terms of distance fit).
Hint: For debugging, a good idea is to make an artificial image that is easily segmented, and to pass good
cluster centers to the function to start from.
The script Demo1.m is provided, which does the following:
1) Loads t1 t2 and pd images
2) Applies k-means clustering with k=8 and random initialization
3) Creates two new images that encode the x and y coordinates of each pixel in the image
4) Adds these to the t1 t2 pd values so that each feature vector is both intensity and location
5) Repeats k-mean clustering to this image and displays the results
Figure below shows an example output of the program
KMeans with t1 t2 pd KMeans with t1 t2 pd X Y
Note that your result can be different. For example, the segment 1 (white color) can be another brain
region (since cluster centers are initially randomly located). Therefore, the below result can be obtained by
running the program another time:
KMeans with t1 t2 pd KMeans with t1 t2 pd X Y