5.1. Tutorial 1: Basic Land Cover Classification

The following is a basic tutorial about the land cover classification using the Semi-Automatic Classification Plugin (SCP). It is assumed that you have a basic knowledge of QGIS. Following the video of the tutorial.

https://www.youtube.com/watch?v=7SZDCFXjIbA

5.1.1. Tutorial 1: Basic Land Cover Classification

This is a basic tutorial about the use of SCP for the classification of a multispectral image. It is recommended to read the Короткий вступ до дистанційного зондування before following this tutorial.

The purpose of the classification is to identify the following land cover classes:

  1. Water;

  2. Built-up;

  3. Vegetation;

  4. Soil.

The basic steps are:

  1. the definition of input data (image bands) in a Band set;

  2. the creation of a Training input to collect training areas to train the classification algorith;

  3. the Classification of input data.

5.1.1.1. Download the Data

Other tutorials will show how to search and download satellite images within SCP. In this tutorial we are going to use a Супутник Sentinel-2 image, already converted to reflectance and clipped to the study area, downloading a .zip file (which contains modified Copernicus Sentinel data 2023).

The study area of this tutorial covers part of the Lake Garda in the Northern Italy. Download the .zip file from this link and extract the directory containing the image bands.

5.1.1.2. Define the Band set and create the Training Input File

We are going to use a subset of Супутник Sentinel-2 image (Copernicus land monitoring services) and use the bands illustrated in the following table.

Sentinel-2 Bands

Central Wavelength [micrometers]

Resolution [meters]

Band 2 - Blue

0.490

10

Band 3 - Green

0.560

10

Band 4 - Red

0.665

10

Band 5 - Vegetation Red Edge

0.705

20

Band 6 - Vegetation Red Edge

0.740

20

Band 7 - Vegetation Red Edge

0.783

20

Band 8 - NIR

0.842

10

Band 8A - Vegetation Red Edge

0.865

20

Band 11 - SWIR

1.610

20

Band 12 - SWIR

2.190

20

First, we need to define the Band set which is the input image for SCP classification. Open the tab Band set clicking the button bandset_tool in the SCP menu or the SCP dock.

Click the button open_file to select the .tif files from the extracted directory to the Band set tab.

Порада

It is possible to define multiple Band sets. It is also possible to add to a Band set bands that are already loaded in QGIS. Each Band set definition is saved with the QGIS project.

In the table Band set definition, we need to order the band names in ascending order and assign the center wavelength to each bands (required for spectral signature calculation). We can do this in one step by selecting Sentinel-2 in the Wavelength list of the Band quick settings.

_images/tutorial_1_band_set_1.png

Definition of a band set

We can display a Кольоровий композит of bands: Near-Infrared, Red, and Green.

Порада

If a Band set is defined, a temporary virtual raster (named Virtual Band Set 1) is created automatically, which allows for the display of a Кольоровий композит.

In the Working toolbar, click the list RGB= and select the item 7-3-2 (corresponding to the band numbers in Band set). You can see that Virtual Band Set 1 is added to QGIS Layers as multiband image, and the displayed bands correspond to the selected color composite.

Because we selected Near-Infrared, Red, and Green bands, in the map, vegetation is highlighted in red. Selecting the color composite 3-2-1, natural colors would be displayed.

_images/tutorial_1_band_set_2.png

Color composite RGB=7-3-2

After Band set creation, we need to create a Training input file in order to collect Навчальні області (ROIs) and calculate the Спектральна сигнатура thereof (which are required to train the classification algorithm).

In the SCP dock select the tab Training input and click the button new_file to create the Training input (define a name such as training.scpx).

Порада

A Training input is a .scpx file which stores the geometries and the spectral signatures. Once it is created, it is configured with the wavelength properties of the corresponding Band set. To use a Training input create with a different Band set, one should create a new Training input, and then import the existing Training input with import_spectral_library Import library file .

The path of the file is displayed and a vector is added to QGIS layers with the same name as the Training input.

Попередження

In order to prevent data loss, one should not edit the Training input using QGIS vector tools.

_images/tutorial_1_training_input_1.png

Definition of Training input in SCP

5.1.1.3. Create the ROIs

We are going to create ROIs defining the Класи та макрокласи. Each ROI is identified by a Class ID (i.e. C ID), and each ROI is assigned to a land cover class through a Macroclass ID (i.e. MC ID).

Macroclasses are composed of several materials having different spectral signatures; in order to achieve good classification results we should separate spectral signatures of different materials, even if belonging to the same macroclass. Thus, we are going to create several ROIs for each macroclass (setting the same MC ID, but assigning a different C ID to every ROI).

We are going to use the Macroclass IDs defined in the following table.

Macroclass name

Macroclass ID

Water

1

Built-up

2

Vegetation

3

Soil

4

Порада

ROIs can be created by manually drawing a polygon or with an automatic region growing algorithm.

In the map zoom over the dark blue area in the upper left corner of the image which is a water body. To manually create a ROI inside the dark area, click the button manual_ROI in the Working toolbar. Left click on the map to define the ROI vertices and right click to define the last vertex closing the polygon. An orange semi-transparent polygon is displayed over the image, which is a temporary polygon (i.e., it is not saved in the Training input).

Порада

You can draw temporary polygons (the previous one will be overridden) until the shape covers the intended area.

_images/tutorial_1_rois_1.png

A temporary ROI created manually

If the shape of the temporary polygon sufficiently covers the water area, we can save it to the Training input.

Open the Training input to define the Класи та макрокласи . In the ROI & Signature list set MC ID = 1 and MC Name = Water; also set C ID = 1 and C Name = Lake. Now click save_roi to save the ROI in the Training input.

After a few seconds, the ROI is listed in the ROI & Signature list and the spectral signature is calculated (because checkbox Signature is checked).

_images/tutorial_1_rois_2.png

The ROI saved in the Training input

As you can see, the C ID in ROI & Signature list is automatically increased by 1. Saved ROI is displayed as a dark polygon in the map and the temporary ROI is removed. Also, in the ROI & Signature list you can notice that the Type is RS (i.e., ROI and spectral signature), meaning that the ROI spectral signature was calculated and saved in the Training input.

Now we are going to create a second ROI for the built-up class using the automatic region growing algorithm. Zoom near the center of the image. In Working toolbar set the Dist value to 0.03 . Click the button roi_single in the Working toolbar and click over the light blue area of the map. After a while the orange semi-transparent polygon is displayed over the image.

Порада

Dist value should be set according to the range of pixel values; in general, increasing this value creates larger ROIs.

_images/tutorial_1_rois_3.png

A temporary ROI created with the automatic region growing algorithm

In the ROI & Signature list set MC ID = 2 and MC Name = Built-up ; also set C ID = 2 (it should be already set) and C Name = Buildings.

_images/tutorial_1_rois_4.png

The ROI saved in the Training input

Again, the C ID in ROI & Signature list is automatically increased by 1.

Create a ROI for the class Vegetation (red pixels in color composite RGB=7-3-2) and a ROI for the class Soil (bare soil or low vegetation) (yellow pixels in color composite RGB=7-3-2) following the same steps described previously. The following images show a few examples of these classes identified in the map.

_images/tutorial_1_rois_5.png

Vegetation. Color composite RGB = 7-3-2

_images/tutorial_1_rois_6.png

Soil. Color composite RGB = 7-3-2

Порада

It is possible to display the Spectral signatures of created ROIs in the sign_plot Spectral Signature Plot.

5.1.1.4. Create a Classification Preview

The classification process is based on collected ROIs (and spectral signatures thereof). It is useful to create a Classification preview in order to assess the results (influenced by spectral signatures) before the final classification. In case the results are not good, we can collect additional ROIs to better classify land cover.

Before running a classification (or a preview), set the color of land cover classes that will be displayed in the classification raster. In the ROI & Signature list, double click the color (in the column Color) of each ROI to choose a representative color of each class. Also, we need to set the color for macroclasses in ROI & Signature list.

_images/tutorial_1_preview_1.png

Definition of class colors

Now we need to select the classification algorithm. In this tutorial we are going to use the Максимальної вірогідності.

Open the tool Classification to set the use of classes or macroclasses. Check Use checkbox Class ID and in Algorithm select the Maximum Likelihood. The input band set is 1 because it is the number of the band set containing the image (bands) that we want to classify.

_images/tutorial_1_preview_2.png

Setting the algorithm and using C ID

In Classification preview set Size = 300; click the button preview and then left click a point of the image in the map. The classification process should be rapid, and the result is a classified square centered in the clicked coordinates.

_images/tutorial_1_preview_3.png

Classification preview displayed over the image using C ID

Previews are temporary rasters (deleted after QGIS is closed) placed in a group named Class_temp_group in the QGIS panel Layers. Now in Classification check Use checkbox MC ID and click the button preview_redo in Classification preview. The preview now represents the colors defined for macroclass.

_images/tutorial_1_preview_4.png

Classification preview displayed over the image using MC ID

Порада

It is useful to perform a classification preview every time a ROI (or a spectral signature) is added to the ROI & Signature list, in order to assess the contribution thereof to the classification; if the ROI causes errors, it can be removed from the Training input with the button delete_signature.

5.1.1.5. Create the Classification Output

Assuming that the results of classification previews show a good agreement with the image (i.e. pixels are assigned to the correct class defined in the ROI & Signature list), we can perform the actual land cover classification of the whole image.

In Classification check Use checkbox Macroclass ID. Click the button Run run and define the path of the classification output, which is a raster file (.tif).

_images/tutorial_1_class_1.png

Result of the land cover classification

Порада

If checkbox Play sound when finished is checked in Calculation process settings, a sound is played when the process is finished.

Well done! You have just performed your first land cover classification.

However, you can see that there are several classification errors, because the number of ROIs (spectral signatures) is insufficient.

_images/tutorial_1_class_2.png

Example of error: Soil classified as Built-up

In other tutorials we are going to learn about the download and preprocessing of bands, the classification algorithms, and the postprocessing of classifications.