
University of Central Florida
CAP5415 - Computer Vision
Problem Set 3
Fall 2008
Assigned: Friday, November 7, 2008
Due: Tuesday, November 18, 2008
Introduction
In your writeup, described the steps you completed for each problem and show the results. Readability will
be part of your grade.
1 Image Clustering with the k-means Algorithm
In class, we discussed how images could be segmented by grouping the pixels into clusters. In this problem,
you will use the k-means algorithm to group pixels into segments.
1. Implement a function im2featurevec that takes an image with NPpixels and returns a matrix (2D
array) with NProws and Mcolumns per row. Each of the Mcolumns will denote a single feature
response. Initially, there will be five features: R,G,B,x, and y.
2. Implement the k-means algorithm. Assuming that there are NCclusters, the basic steps of the algo-
rithm are:
•Initialize the algorithm by either initializing the cluster assignments or the cluster locations
•Until convergence criterion is satisfied:
–Assign each point to the nearest cluster center
–Ensure that each center has at least one point assigned to it. One possible heuristic for filling
in empty clusters is to choose a random point that is far from the cluster center.
–Set each cluster center to the average of the points assigned to it. You will average each
dimension of the vectors separately.
The input to your function should be an array of points and the number of cluster centers. The output
should be the cluster to which each point is assigned and the cluster centers.
3. Write a function that takes an image and returns an image where each pixel contains the cluster number
assigned to that cluster. Write a second function that takes this image and displays the boundaries. A
simply method for findind the boundaries is to filter the image with vertical and horizontal derivative
filters, compute the gradient magnitude, then threshold that value.
4. Test your function on the images provided.
5. Problem 1.1 does not ask you to normalize the feature vectors. To see the effect of normalizing the
vectors, write a new function that creates the feature matrix as before, but now subtracts the mean
from each column, so that each column has a zero mean. In addition, the variance of each column
should be divided by a constant so that the quantity:
1