5.1. Tutorial 1

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.

5.1.1. Tutorial 1: Your First 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 Brief Introduction to Remote Sensing before 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 study area of this tutorial is Matera (Basilicata, Italy) which is a city in the Southern Italy. Matera is the site of a Center of the Italian Space Agency (ASI) specialized in remote sensing, which has several purposes, in particular to acquire, process and store remote sensing data.

Following the video of this tutorial.

http://www.youtube.com/watch?v=Ceyhm3DlZNY

5.1.1.1. Download the Data

We are going to download a Sentinel-2 Satellite 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
TIP : In case of slow internet connection you can download an image subset from this archive (about 30 MB, © Copernicus Sentinel data 2020 downloaded from https://scihub.copernicus.eu/), unzip the downloaded file, and skip to Preprocess the data.

Start QGIS and the SCP. Open the tab Download products clicking the button download in the Home, or in the SCP menu,

In the tab Download products click the button osm_add to display the OpenStreetMap tiles (© OpenStreetMap contributors) in the QGIS map, licensed as CC BY-SA (Tile Usage Policy ).

We are searching a specific image acquired on 8 July 2020 because it is cloud free (however you can use any other Sentinel-2 image). In Search parameters enter the point coordinates:

  • UL: 16.5 / 40.7

  • LR: 16.7 / 40.6

    TIP : In general it is possible to define the area coordinates clicking the button pointer , then left click in the map for the UL point and right click in the map for the LR point.

Select Sentinel-2 from the Products input_list and set:

  • Date from: 2020-07-08
  • to: 2020-07-08
_images/tutorial_1_1_01.jpg

Search products

Now click the button Find search_images and after a few seconds the image will be listed in the Product list. Click the ProductID L2A_T33TXF_A026345_20200708T094035 in the table to display a preview that is useful for assessing the quality of the image and the cloud cover.

_images/tutorial_1_1_02.jpg

Search result

Now click the button image_preview to load the preview in the map.

_images/tutorial_1_1_03.jpg

Image preview

We can also select which bands to be downloaded according to our purpose. In particular, select the tab Download options and check only the Sentinel-2 bands (that will be used in this tutorial): 2, 3, 4, 5, 6, 7, 8, 8A, 11, 12 and the ancillary data.

_images/tutorial_1_1_04.jpg

Download options

For the purpose of this tutorial, uncheck the option checkbox Preprocess images (you should usually leave this checked) because we are going to preprocess the image in Preprocess the data. To start the image download, click the button RUN run and select a directory where bands are saved. The download could last a few minutes according to your internet connection speed. The download progress is displayed in a bar.

TIP : The option checkbox Only if preview in Layers allows for downloading only images in the result table which are loaded as previews in the map. If this option is unchecked, all the products in the list are downloaded.

After the download, all the bands are automatically loaded in the map.

_images/tutorial_1_1_05.jpg

Download of Sentinel-2 bands

5.1.1.2. Clip the Data

For for limiting the study area (and reducing the processing time) we can clip the image.

First, we need to define a Band set containing the bands to be clipped. Several tools in SCP use the Band sets, which are numbered sets of raster bands and related information (such as center wavelength and acquisition date).

Open the tab Band set clicking the button bandset_tool in the SCP menu or the SCP dock.

Click the button reload to refresh the layer list, and select the bands: 2, 3, 4, 5, 6, 7, 8, 8A, 11, and 12; then click plus to add selected rasters to the Band set 1.

_images/tutorial_1_clip_1.jpg

Band set for clipping

In Передоброблення open the tab Clip multiple rasters. We are going to clip the Band set 1 which contains Sentinel-2 bands.

Click the button pointer and select an area such as the following image (left click in the map for the UL point and right click in the map for the LR point), or enter the following values:

  • UL: 623830 / 4505410
  • LR: 645330 / 4494350
_images/tutorial_1_clip_2.jpg

Clip area

Click the button RUN run and select a directory where clipped bands are saved. New files will be created with the file name prefix defined in Output name prefix. When the process is completed, clipped rasters are loaded and displayed.

_images/tutorial_1_clip_3.jpg

Clipped bands

5.1.1.3. Preprocess the data

The downloaded product is a Sentinel-2 Level 2A image, which is already atmospherically corrected (Level 1C images require atmospherical correction as described in Image conversion to reflectance). Nevertheless, preprocessing is required to convert pixel values to a decimal value of reflectance.

Conversion to reflectance (see Radiance and Reflectance) can be performed automatically. The metadata file (a .txt file whose name contains MTL) downloaded with the images contains the required information for the conversion.

In order to convert bands to reflectance, open the Передоброблення clicking the button preprocessing in the SCP menu or the SCP dock, and select the tab Sentinel-2.

Click the button Directory containing Sentinel-2 bands open_dir and select the directory of clipped Sentinel-2 bands. The list of bands is automatically loaded in the table Metadata.

You can ignore Select metadata file because this conversion doesn’t require additional information.

Sentinel-2 Level 2A images don’t require the DOS1 Correction; if it was a Level 1C image we should enable the option checkbox Apply DOS1 atmospheric correction.

TIP : In general, it is recommended to perform the DOS1 atmospheric correction for the entire image (before clipping the image) in order to improve the calculation of parameters based on the image.

For the purpose of this tutorial, uncheck the option checkbox Create Band set and use Band set tools because we are going to define this in the following step Define the Band set and create the Training Input File.

In order to start the conversion process, click the button RUN run and select the directory where converted bands are saved.

_images/tutorial_1_conversion_1.jpg

Sentinel-2 conversion to reflectance

After a few minutes, converted bands are loaded and displayed (file name beginning with RT_). If checkbox Play sound when finished is checked in Classification process settings, a sound is played when the process is finished.

We can remove all the bands loaded in QGIS layers except the ones whose name begin with RT_.

_images/tutorial_1_conversion_2.jpg

Converted Sentinel-2 bands

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

Now 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.

In Band set definition click the button reset to clear all the bands from active band set created during the previous steps.

Click the button reload to refresh the layer list, and select all the converted bands; then click plus to add selected rasters to the Band set.

In the table Band set definition order the band names in ascending order (click order_by_name to sort bands by name automatically). Finally, select Sentinel-2 from the list Wavelength quick settings, in order to set automatically the Center wavelength of each band and the Wavelength unit (required for spectral signature calculation).

_images/tutorial_1_band_set_1.jpg

Definition of a band set

We can display a Color Composite of bands: Near-Infrared, Red, and Green: 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 image colors in the map change according to the selected bands, and vegetation is highlighted in red (if the item 3-2-1 was selected, natural colors would be displayed).

TIP : If a Band set is defined, a temporary virtual raster (named Virtual Band Set 1) is created automatically, which allows for the display of Color Composite. In order to speed up the visualization, you can show only the virtual raster and hide all the layers in the QGIS Layers.
_images/tutorial_1_band_set_2.jpg

Color composite RGB=7-3-2

Now we need to create the Training input in order to collect Training Areas (ROIs) and calculate the Spectral Signature thereof (which are used in classification).

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.scp). 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, you should not edit this layer using QGIS functions).

_images/tutorial_1_training_input_1.jpg

Definition of Training input in SCP

5.1.1.5. Create the ROIs

We are going to create ROIs defining the Classes and Macroclasses. 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 used the Macroclass IDs defined in the following table.

Macroclasses
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 lower 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).

TIP : You can draw temporary polygons (the previous one will be overridden) until the shape covers the intended area.
_images/tutorial_1_rois_1.jpg

A temporary ROI created manually

If the shape of the temporary polygon is good we can save it to the Training input.

Open the Training input to define the Classes and Macroclasses . 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.jpg

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, 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 in the upper region of the image. In Working toolbar set the Dist value to 0.05 . 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.

TIP : Dist value should be set according to the range of pixel values; in general, increasing this value creates larger ROIs.
_images/tutorial_1_rois_5.jpg

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_6.jpg

The ROI saved in the Training input

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

After clicking the button roi_single in the Working toolbar you should notice that the cursor in the map displays a value changing over the image. This is the NDVI value of the pixel beneath the cursor (NDVI is displayed because the function checkbox Display is checked in ROI options). The NDVI value can be useful for identifying spectrally pure pixels, in fact vegetation has higher NDVI values than soil.

For instance, move the mouse over a vegetation area and left click to create a ROI when you see a local maximum value. This way, the created ROI and the spectral signature thereof will be particularly representative of healthy vegetation.

_images/tutorial_1_rois_7.jpg

NDVI value of vegetation pixel displayed in the map. Color composite RGB = 7-3-2

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_3_7.jpg

Vegetation. Color composite RGB = 4-3-2

_images/tutorial_1_3_8.jpg

Soil. Color composite RGB = 4-3-2

5.1.1.6. Assess the Spectral Signatures

Spectral signatures are used by Classification Algorithms for labelling image pixels. Different materials may have similar spectral signatures (especially considering multispectral images) such as built-up and soil. If spectral signatures used for classification are too similar, pixels could be misclassified because the algorithm is unable to discriminate correctly those signatures. Thus, it is useful to assess the Spectral Distance of signatures to find similar spectral signatures that must be removed. Of course the concept of distance vary according to the algorithm used for classification.

One can simply assess spectral signature similarity by displaying a signature plot. In order to display the signature plot, in the ROI & Signature list highlight two or more spectral signatures (with click in the table), then click the button sign_plot. The Spectral Signature Plot is displayed in a new window. Move and zoom inside the Plot to see if signatures are similar (i.e. very close). Double click the color in the Plot Signature list to change the line color in the plot.

We can see in the following figure a signature plot of different materials.

_images/tutorial_1_sig_1.jpg

Spectral plot

In the plot we can see the line of each signature (with the color defined in the ROI & Signature list), and the spectral range (minimum and maximum) of each band (i.e. the semi-transparent area colored like the signature line). The larger is the semi-transparent area of a signature, the higher is the standard deviation, and therefore the heterogeneity of pixels that composed that signature. Spectral similarity between spectral signatures is highlighted in orange in the Plot Signature list.

Additionally, we can calculate the spectral distances of signatures (for more information see Spectral Distance). Highlight two or more spectral signatures with click in the table Plot Signature list, then click the button calculate_spectral_distances; distances will be calculated for each pair of signatures. Now open the tab Spectral distances; we can notice that similarity between signatures vary according to considered algorithm.

_images/tutorial_1_sig_2.jpg

Spectral distances

For instance, two signatures can be very similar for Spectral Angle Mapping (very low Spectral Angle), but quite distant for the Maximum Likelihood (Jeffries-Matusita Distance value near 2). The similarity of signatures is affected by the similarity of materials (in relation to the number of spectral bands available); also, the way we create ROIs influences the signatures.

Spectral signature values, standard deviation and other details such as the number of ROI pixels are displayed in the Signature details.

We need to create several ROIs (i.e. spectral signatures) for each macroclass (repeating the steps in Create the ROIs), assigning a unique C ID to each spectral signature, and assess the spectral distance thereof in order to avoid the overlap of spectral signatures belonging to different macroclasses.

In the list RGB= of the Working toolbar type 10-3-2 (you can also use the tool RGB list). Using this color composite, urban areas are grey, bare soils are light green, and vegetation is brown. This color composite RGB = 10-3-2 can help the identification of soils more than natural color composite (RGB = 3-2-1).

_images/tutorial_1_rois_4.jpg

Color composite RGB = 3-7-10

TIP : Change frequently the Color Composite in order to clearly identify the materials at the ground; use the mouse wheel on the list RGB= of the Working toolbar for changing the color composite rapidly; also use the buttons cumulative_stretch and std_dev_stretch for better displaying the Input image (i.e. image stretching).

It is worth mentioning that you can show or hide the temporary ROI clicking the button radiobutton ROI in Working toolbar.

5.1.1.7. 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 more 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.jpg

Definition of class colors

Now we need to select the classification algorithm. In this tutorial we are going to use the Maximum Likelihood.

Open the tool Classification to set the use of classes or macroclasses. Check Use checkbox C ID and in Algorithm select the Spectral Angle Mapping. 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_3.jpg

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 clicked point.

_images/tutorial_1_preview_4.jpg

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.

_images/tutorial_1_preview_5.jpg

Classification preview displayed over the image using MC ID

We can see that now there are only 4 colors representing the macroclasses.

TIP : When loading a previously saved QGIS project, a message could ask to handle missing layers, which are temporary layers that SCP creates during each session and are deleted afterwards; you can click Cancel and ignore these layers; also, you can delete these temporary layers clicking the button remove_temp in Working toolbar.

In general, it is good to perform a classification preview every time a ROI (or a spectral signature) is added to the ROI & Signature list. Therefore, the phases Create the ROIs and Create a Classification Preview should be iterative and concurrent processes.

5.1.1.8. Create the Classification Output

Assuming that the results of classification previews were good (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 MC ID. In the Classification output click the button run and define the path of the classification output, which is a raster file (.tif). If checkbox Play sound when finished is checked in Classification process settings, a sound is played when the process is finished.

_images/tutorial_1_class_1.jpg

Result of the land cover classification

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.jpg

Example of error: Soil classified as Built-up

_images/tutorial_1_class_3.jpg

Example of error: Water bodies classified as Built-up

We can improve the classification using some of the tools that will be described in other tutorials.