Computer Vision · Intermediate level

Intermediate level · Module 1: Machine Learning for Image Analysis · Lesson 2 of 3

Clustering and Exploring Image Data

Learners use k-means to group colours (for example separating vegetation, soil and water in an aerial photo) and PCA to visualise how well classes separate in a dataset.

In this lesson you will

  • Segment colours with k-means
  • Visualise image datasets with PCA

Key concepts

k-means clusteringcluster centres as coloursPCA2-D projectionclass overlap

The lesson

k-means groups pixels into k clusters by colour. On an aerial or satellite photo, k = 3 or 4 often separates vegetation, bare soil, water and built areas well enough for a first estimate of land cover, without any labels.

PCA projects high-dimensional features (for example HOG vectors) onto two dimensions for plotting. If the classes form separate clouds, simple models will work; if they overlap heavily, stronger features are needed.

Unsupervised results need checking: clusters are groups of similar colours, not guaranteed land-cover classes. Compare them with what a person sees in the image.

Step by step

  1. Reshape an aerial image to a list of pixels and run KMeans with k = 4.
  2. Recolour each pixel with its cluster centre and display the result.
  3. Compute the share of each cluster.
  4. Plot a PCA projection of HOG features for two datasets and compare the overlap.

Practice activity

Produce a k-means land-cover sketch for two aerial images and a PCA plot of the project features.

Expected result: Plausible cluster maps with checked interpretations and a PCA plot that explains classifier difficulty.

Check your understanding

  1. Does a k-means cluster always correspond to a land-cover class?

    Show answer

    No. It groups similar colours, which must be checked by a person.

  2. What does heavy class overlap in a PCA plot suggest?

    Show answer

    Simple features and models will struggle; stronger features are needed.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.