top of page

Yujin Kim,

PhD

Orfeo ToolBox (OTB, Image Processing Library) Plugin in QGIS

Supervised Image Classification – Random Forest

Aim

The aim of this machine learning task is to detect objects in London’s Sentinel image through supervised classification. The random forest method was used through an OTB [1] plugin in QGIS (v.3.28.12) [2]. Random forest is a machine learning method that “combines the output of multiple decision trees to reach a single results [3].”

Approach and Process

A Sentinel image of London [4] was imported, and training and validation datasets were created as shape files (.shp) using Semi-Automatic Classification plugin [5] (Fig. 3.1). The categories were labelled as built environments, vegetation, water and cloud. Training and validation were processed with a Random Forest algorithm using TrainImagesClassifier in the OTB plugin. The results were exported into a text (.txt) file, which was processed to create a classified image, using ImageClassifier (Fig. 3.2).

Fig. 3.1. Training and validation datasets in shape files imported into QGIS

Fig. 3.2. TrainImagesClassifier and Image Classifier in the OTB plugin, QGIS

Note that a false colour image was used by changing the RGB expression, using bands. This was because this expression helps enhance the features of image pixels. Otherwise, some parts of an image are invisible or less visible.

Results

London’s Sentinel image [4] (Fig. 3.3) was classified into four categories: cloud, water, vegetation and built environments (Fig. 3.4). The assessment of the accuracy of the results is described in the next section.

Fig. 3.3. London’s Sentinel image [4] in false colour.

Fig. 3.4. Classified image by Random Forest supervised machine learning.

Assessment of the Result Accuracy

The accuracy assessment of an outcome was undertaken qualitatively and quantitatively.

1) Qualitative Analysis – Observation and Comparison

By observing and comparing the original input image with the outcome, the accuracy of a classified image can be explained qualitatively. The River Thames and the lakes in Fig.3.4 were classified as relatively distinctive. However, the shadows of the clouds were the same colour as the River Thames (black), so they were classified as water. Built environments and vegetation were classified fairly well, although there were some errors. However, the clouds in grey colour were represented as vegetation while those in white were categorised correctly as clouds.
These errors were made because: 1) the categories were labelled by a user (myself), and the labels were defined by colour (e.g. white colour as clouds, etc.). However, the parts with clouds were in black colour, and so these were classified as water. This can be enhanced by defining sub-categories (Class) as well as main categories (Macroclass), such as Cloud (Macroclass), cloud A in grey (Class ID 1) and cloud B in white (Class ID 2). Nonetheless, as both the water and shadows of the clouds were in black, it is difficult to differentiate them. In this case, unsupervised learning worked better, as it can classify the features of image pixels using a computational algorithm (see Fig. 2.3 in Section 1.1.2).
2) Another reason the errors occurred was because the number of classifications was only four. This limited number of classifications could not classify the various features of the pixels.

2) Quantitative Analysis

Accuracy assessments can be undertaken quantitatively, using a confusion matrix created by the Random Forest machine learning (Table 3.1). Overall accuracy can be calculated as Equation 3.1 [6]:

Table 3.1. Confusion matrix

User accuracy can be calculated in accordance with Equation 3.2 [6], meaning “how often the class on the map will actually be present on the ground. This is referred to as reliability [6]”:

Producer accuracy can be calculated with Equation 3.3 [6], meaning “how often are real features on the ground correctly shown on the classified map or the probability that a certain land cover of an area on the ground is classified [6]”:

It should be noted that from the 1) qualitative analysis by comparing the images, some errors were discovered (e.g. shadows of clouds mistakenly classified as water, etc.) However, in the 2) quantitative analysis, the accuracy assessments were optimistic. This was because the quantitative analysis was based on reference (validation) data that were also labelled by the user (myself). When the reference data were defined, they were chosen from different locations than those in the training data. However, the definitions of the reference data were also based on colours; therefore, the user selected the pixels with the same or similar colours of each class (e.g. clouds in white). Thus, the accuracy of the results was overestimated from comparing the classification data with the references in the confusion matrix.

References

[1] QGIS interface, https://www.orfeo-toolbox.org/CookBook/QGISInterface.html.
[2] QGIS, https://www.qgis.org/en/site/.
[3] What is random forest?, https://www.ibm.com/topics/random-forest.
[4] Sentinel-2 MSI: MultiSpectral Instrument, Level-2A. Dataset Provider: European Union/ESA/Copernicus.
https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR.
[5] QGIS Python Plugins Repository, Semi-Automatic Classification plugin,
https://plugins.qgis.org/plugins/SemiAutomaticClassificationPlugin/.
[6] Accuracy Metrics. https://gsp.humboldt.edu/olm/Courses/GSP_216/lessons/accuracy/metrics.html.

bottom of page