Skip to Content
Programming Computer Vision with Python
book

Programming Computer Vision with Python

by Jan Erik Solem
June 2012
Beginner to intermediate
260 pages
6h 28m
English
O'Reilly Media, Inc.
Content preview from Programming Computer Vision with Python

Chapter 6. Clustering Images

This chapter introduces several clustering methods and shows how to use them for clustering images for finding groups of similar images. Clustering can be used for recognition, for dividing data sets of images, and for organization and navigation. We also look at using clustering for visualizing similarity between images.

6.1 K-Means Clustering

K-means is a very simple clustering algorithm that tries to partition the input data in k clusters. K-means works by iteratively refining an initial estimate of class centroids as follows:

  1. Initialize centroids μi, i = 1 . . . k, randomly or with some guess.

  2. Assign each data point to the class ci of its nearest centroid.

  3. Update the centroids as the average of all data points assigned to that class.

  4. Repeat 2 and 3 until convergence.

K-means tries to minimize the total within-class variance

image with no caption

where xj are the data vectors. The algorithm above is a heuristic refinement algorithm that works fine for most cases, but it does not guarantee that the best solution is found. To avoid the effects of choosing a bad centroid initialization, the algorithm is often run several times with different initialization centroids. Then the solution with lowest variance V is selected.

The main drawback of this algorithm is that the number of clusters needs to be decided beforehand, and an inappropriate choice will give poor clustering results. The ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Joseph Howse, Joe Minichino

Publisher Resources

ISBN: 9781449341916Errata PageSupplemental Content