Applying hierarchical clustering on images

We encountered the concept of hierarchical clustering in Chapter 9, Ensemble Learning and Dimensionality Reduction. In this recipe, we will segment an image by hierarchically clustering it. We will apply agglomerative clustering O(n3), which is a type of hierarchical clustering.

In agglomerative clustering, each item is assigned its own cluster at initialization. Later, these clusters merge (agglomerate) and move up the hierarchy as needed. Obviously, we only merge clusters that are similar by some measure.

After initialization, we find the pair that are closest by some distance metric and merge them. The merged cluster is a higher-level cluster consisting of lower-level clusters. After that, we again find ...

Get Python Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.