From this satellite image, we want to create a land use land cover map by extracting various land use land cover classes such as built-up, vegetation (forest and grassland), water, and bare land. To achieve this, there are several machine learning approaches:
- Supervised machine learning
- Unsupervised machine learning
If these concepts are new to you, or you would like to refresh your understanding, the following two resources cover urban land cover and image classification respectively:
Machine learning has many applications, and image classification is one of the most common. It is an expansive subject of study; however, the main aim of this article is to demonstrate its capabilities in QGIS and provide a starting point for further exploration.
Steps for image classification using machine learning
- Training data collection
- Signature data generation
- Apply a classification algorithm
- Accuracy assessment
The process varies slightly depending on whether supervised or unsupervised machine learning is used. When working in QGIS through a plugin, most of the lower-level steps are abstracted from the user, with the software handling the underlying processes automatically.
Image classification in QGIS
This workflow uses the Semi-Automatic Classification Plugin (SCP), a free open-source plugin for QGIS that provides tools for machine learning and digital image analysis. SCP allows for the classification of remote sensing images and includes tools for the download, preprocessing, and postprocessing of imagery. To install it, go to the Plugins menu in the top toolbar, search for “Semi-Automatic Classification Plugin”, and install it.
After installing SCP, an SCP menu will be added to the top toolbar and an SCP dock will appear on the left side of the QGIS interface. To carry out preprocessing on your image, open the main SCP interface and navigate to Band set, which provides a range of tools for both pre-classification and post-classification operations. If your image contains noise, apply any necessary corrections before proceeding to the next stage.
Unsupervised machine learning in QGIS
Unsupervised classification clusters pixels in a dataset based on their spectral statistics alone, without requiring user-defined training classes.
K-means clustering algorithm
K-means is an iterative algorithm that groups pixels into a predefined number of non-overlapping clusters, with each pixel belonging to only one cluster. A pixel is assigned to a cluster based on the squared Euclidean distance between the pixel’s spectral values and each cluster’s centroid; the pixel is assigned to the nearest centroid. The centroids are then recalculated, and the process repeats until the cluster assignments stabilise. When performing K-means clustering, you must manually assign class names to the resulting clusters based on your knowledge of the area. K-means is mainly used as an exploratory algorithm for gaining an intuition of how the data is structured, rather than as a definitive classification method.
Supervised machine learning in QGIS
Supervised classification clusters pixels into classes based on user-defined training data, which the algorithm uses as a reference during classification.
Training sample selection and labelling in QGIS
How many distinct classes can be extracted from a satellite image? This depends on factors such as the spatial resolution of the imagery, the intended use case, and the homogeneity of the study area, among other considerations. For this example, five classes are used: forest (thick vegetation), built-up, grassland, bare land, and water.
In the SCP Dock, click on Training input to open a dialog for creating training samples. You will need to enter a Macroclass ID (MC ID) and a Class ID (C ID). SCP supports sub-classes within a macroclass: for example, within the built-up macroclass you could create sub-classes for informal settlements and formal settlements. Create a new .scp training input file using the “Create new training input” button at the top of the SCP dock menu.
After entering the class name and class ID, use the “Create ROI (Region of Interest) Polygon” tool to select training samples from the image. To save the selected samples, use the “Save temporary ROI to training input” button at the bottom of the SCP dock menu. Repeat this process for all classes to build up a full set of training signatures.
You can view the spectral reflectance values of the different training sample classes using the SCP Spectral Signature Plot. To check the quality of your training samples, use the classification preview option: click the preview button, then click on an area of the image to see a preview of the classification output for that location. If the preview is a good representation of the land cover on the ground, proceed to run the full classification algorithm. Otherwise, return to the training sample selection step and refine your samples.
Maximum likelihood algorithm
The maximum likelihood algorithm assigns each pixel to the class for which it has the highest probability of membership, based on the statistical properties (mean and covariance) of the training samples. A minimum probability threshold can be specified; if the highest probability for a pixel falls below that threshold, the pixel remains unclassified.
After creating sufficient training samples, open the SCP main interface, navigate to Band processing, and select Classification to open the classification dialog. In addition to maximum likelihood, SCP also supports minimum distance and spectral angle mapping algorithms, all of which are included in the plugin.
Select whether to use the Macroclass ID or the Class ID for classification. Try several threshold values to determine which produces the best results. After providing all parameters, click Run and specify a file path to save the classification output. Review the results, and if they are unsatisfactory, adjust the parameters or refine the training samples. A good understanding of the study area is essential when evaluating classification quality.
Accuracy assessment
After classification, the integrity of the results must be verified to ensure the output is reliable. Accuracy assessment is performed by comparing the classification results against ground truth data or a higher-accuracy reference dataset. The standard method is to collect a set of randomly sampled reference points and compare them to the classified output in a confusion matrix (also called an error matrix).
From the confusion matrix, several quantitative accuracy metrics can be derived. Overall accuracy expresses the percentage of correctly classified pixels across all classes. The kappa coefficient (Cohen’s kappa) provides a measure of agreement between the classification and the reference data that accounts for the agreement expected by chance alone, making it a more robust indicator than overall accuracy in isolation. Producer’s accuracy (recall) and user’s accuracy (precision) can be derived for each class individually, allowing per-class errors of omission and commission to be identified. SCP includes a dedicated accuracy assessment tool under Postprocessing > Accuracy that automates this process.
Recommended Reading
- How to use the STAC plugin to add satellite imagery to your QGIS project
- Fundamentals of rasters and imagery
- Cloud-optimise your raster data







