# Clustering a set of images using keypoint descriptors

I'm trying to cluster around 16000 images into ~200 clusters, using kmeans with metric as euclidean distance or cosine distance. I understand that i need to extract keypoint descriptors to compute features for each image. I'm looking at SIFT as an option but, SIFT outputs different number of keypoints for each image that i have. How can i use these keypoint descriptors generated by SIFT to make a uniform sized feature vector for every image, so that i can feed these vectors to kmeans. Or should i use any other feature descriptor apart from SIFT?

• I think we're missing some context. Why are you constraining yourself to use $k$-means as the clustering algorithm? Is this an exercise? If so, please provide full information about the exercise and what you've tried. This approach isn't the first one that I would try, so I want to find out whether using $k$-means is a hard requirement and if so why. – D.W. Sep 10 '15 at 17:39
• @D.W. This is not an exercise. And using k-means is not a hard requirement. I didn't know many clustering algorithms so i decided to go with k-means, which i'm a little familiar with. I'm trying to cluster a bunch of tshirt images taken from e-commerce platforms. I also have some attribute information about these images such as sleeve length, collar type, pattern etc. Currently i'm clustering by forming a feature using these attributes. I'm looking to add image features to this existing attribute features that i have, to look if it improves the clustering results. – m_amber Sep 11 '15 at 7:16

I don't know how to do it that way. I would suggest you do it a different way:

1. Define a distance metric that measures the dissimilarity between two metrics. In particular, if $I,J$ are two images, $d(I,J)$ should quantify how dissimilar $I,J$ are -- large values indicate they are very different, small values indicate they are very similar.

2. Use a different clustering algorithm that only needs a distance metric.

For #1, there are many ways of measuring/computing image similarity. If you want to use SIFT as your starting point, you can align the two images and compute some metric based upon the number of keypoints that are well-matched ("inliers") vs the number that aren't ("outliers).

For #2, there are many options. One option is to use hierarchical clustering.

I recommend you spend some time reading through the research literature on measuring image similarity in the computer vision literature. There's lots of work, and many methods proposed and evaluated.

See also https://stackoverflow.com/q/843972/781723 and https://stackoverflow.com/q/4196453/781723. You could also use the TinEye API.