Clustering (kmeans)

Several clustering methods are available in the EnMAP-Box. You can find them in the Processing Toolbox under EnMAP-Box ‣ Clustering. The usual way to apply these methods is to use a Fit … algorithm first and then apply it to an image with Predict Clustering.

This recipe demonstrates the basic workflow of applying clusterers using K-Means clustering (Fit KMeans) and the test dataset.

See also

You can find all the available clustering algorithms here.

  1. Open the test dataset

  2. In the processing toolbox go to EnMAP-Box ‣ Clustering ‣ Fit KMeans

    • Specify enmap_berlin.bsq under Raster
    • Under Output Clusterer specify an output file path and click Run
  3. Now open EnMAP-Box ‣ Clustering ‣ Predict Clustering

    • Select enmap_berlin.bsq as input Raster
    • Under Clusterer click and select the output .pkl file from the Fit KMeans algorithm
    • Specify an output filepath for the transformed raster under Clustering and click Run
    ../../_images/example_kmeans.png

    EnMAP true color image (left) and kmeans cluster result with 8 clusters (right)

Tip

8 clusters is the default of the kmeans algorithm here, if you want to change the number of clusters, run the Fit Kmeans algorithm with a fewer number, by altering the KMeans() function in the Code window to KMeans(n_clusters=4). This will reduce the amount of clusters to 4.