Supervised classification in QGIS

From CUOSGwiki
Jump to navigationJump to search

Purpose and Introduction

Every day thousands of satellite images are taken. To work with these images they need to be processed, e.g. they need to be classified. Since Remote Sensing software can be very expensive this tutorial will provide an open-source alternative: the Semi-automatic-classification plugin (SCP) in QGIS. We will go through a basic supervised land-cover classification with Sentinel-2 Data. This tutorial is one suggestion to use the SCP. After running through the following workflow you will know the SCP better and you will be able to discover more opportunities to work with remote-sensing Data in QGIS. You can also find another tutorial about the SCP here [1]. Feel free to combine both tutorials.

Land cover classification allocate every pixel in a raster image to a defined class depending on the spectral angle. The SCP provides four different algorithms: Maximum Likelihood, Minimum Distance, Spectral Angle mapping and Land Cover Signature Classification.

Installing the Software and SCP

To start the tutorial you have to download the latest version of QGIS which is QGIS 3.4.1. "Bonn" and can be found here[2]. Make sure to download the proper version for your PC (34bit vs. 64bit). After installing the software the Semi-automatic classification Plugin (SCP) must be installed into QGIS. Navigate to the menu at the top to Plugin and select Manage and Install Plugins. Following the picture, the SCP can be found while typing "semi" in the search bar. Click install plugin and now you should be able to see the SCP Dock at the right or left side of your user surface.


SCP.jpg

Obtaining the Data

In this Tutorial, Sentinel-2 Data from the south of Lake Garda, Italy is used to run the classification. The data can be downloaded from the USGS Earth Explorer website here[3]. You can find a explanation how to download data from the Earth Explorer in the Tutorial Remote Sensing Analysis in QGIS. To find the same picture as used in this tutorial search for Lake Garda and select the time period from August to October 2018. Among Data Sets select Sentinel-2 and you should find the following picture:

Sentinel-2image.JPG

ID: L1C_T32TPR_A008056_20180921T101647 Date: 21st of September 2018.

Unpack the Data

The downloaded data is packed in a zip-File. Therefore, you have to unzip the Data before working with it. Afterwards you can find the image data in your home directory under GRANULEL1C_T32TPR_A008056_20180921T101647IMG_DATA. For each band of the satellite Data you can find a separate JPEG file.

Load the Data into QGIS and Preprocess it

To load the Data into QGIS navigate to Layer at the top your user surface. Choose Add Layer, and then Add Raster Layer.... You should see the Data Source Manager now. Leave "File" selected like it is in default. Under Datasets you can navigate to the directory described above where you find the imageries. Make sure to load all JPEG files into QGIS except the file of band 10: T32TPR_20180921T101019_B10. Band 10 is the Cirrus band and is not needed for this approach. It makes the classification even harder as you can imagine watching at it:


Band 10.JPG


Creating a Band set

The next step is to create a band set. Navigate to the SCP button at the top of the user surface and select Band set. Under Multiband image list you can load the images into SCP and then into the Band Set 1. Make sure the layers are in the right order and select Sentinel-2 under Quick wavelength units. The picture below should help to understand these steps.


CreateBandSet.JPG


If you do not want to see a gray scaled image navigate to the SCP toolbar at the top of your surface to RGB and choose 3-2-1 to see true colours.


4-3-2.JPG

Clip the Data

For a basic classification the area covered by the picture is very big. Therefore, we can clip the data and only work with a part of the picture. Navigate to the SCP button at the top of the user surface, under Preprocessing you find clip multiple Raster. Your surface should look similar like in the picture below. Choose Band set 1 which you defined in the previous step.


UserSurface Clip.JPG


To clip the data press the orange button with the plus. Minimize the SCP window and you can now define the area you want to work with while clicking with the right button on your mouse. I suggest to define an area south of the mountains to avoid dealing with mountain shadows in the classification. In addition in the south of the pictures there are no clouds. For instance, choose an area like this:


LakeGarda Clip.JPG


After defining the section under coordinate there should occur numbers. Click run and define an output folder. In the Layer Dock, for each Band (1-9,11,12) a separate Raster Layer, which is resized, occurs.

Automatic Conversion to Surface Reflection

The last preprocessing step is to run an atmospheric correction. Go to SCP, Preprocessing, Sentinel-2 and choose the directory where you saved you clipped data. Check Apply DOS1 atmospheric correction and uncheck only to blue and green bands likely in the sample picture. Since a new band set is needed, it is useful to check Create band set. The solar radiance should be recognized automatically. Click run and define an output folder.


Conversion.JPG


The output files will be named e.g. like this: RT_clip_T32TPR_20180921T101019_B03.

Supervised Classification

We can now begin with the supervised classification. Make sure you see the SCP & Dock at your surface. If not clicking this button OpenSCP.JPG in the tool bar will open it.

Set Region of Interests (ROI)

First, you must create a file where the ROIs can be saved. To do so, click this button:


SCP Dock.JPG


Click the Create a ROI button to create the first ROI. You can define the ROI with mouse clicks, to complete it click right.


Create ROI.JPG


In the following picture the first ROI is in the lake. You can see that the macro class (MC ID) is named Water and the subclass (C ID) Lake. In this tutorial only the macro class will be significant. Save the ROI.


First ROI.JPG


A second option to create an ROI is to activate and ROI pointer. This can be done while clicking the plus in the red box (at the following picture) and defining the radius where the program should look for similar pixels. Your ROI could be look like this:


Built-up ROI.JPG


In this tutorial 4 macro classes will be defined: water, built-up area, healthy vegetation, unhealthy vegetation. Since vegetation is reflecting light in NIR (Near infrared) we can visualize it in a image with false colours and therefore distinguish healthy and unhealthy vegetation. To do so, click right on the layer Virtual Band Set 1 and choose Properties. Define Band 08 (NIR) as red, Band 04 (Red) as green and Band 3 (green) as blue like in the image below.


Editfalsecolours.JPG


Now, the healthy vegetation occurs red while the unhealthy vegetation (e.g. unused fields) occur blue/grey.


Falsecolours.JPG


Keep going setting ROIs for unhealthy and healthy vegetation. Try to be as accurate as possible, to make sure that pixel are assigned to the proper class. In the following picture I show an example of set ROIs:


ROIs.JPG


Before we run the classification we can change the colours of the macro classes in the SCP Dock. Click Macroclass List and double-click on the colour fields:


Changecolours.JPG


Choose a appropriate colour for every class.


Running the classification

Now go the the classification in the SCP Dock. You will notice that there are various options to run the classification. For instance, there are different classification algorithm. Minimum Distance, Maximum Likelihood or Spectral Angle Mapper. Feel free to try all free of them. If you check LCS, the Landcover Signature classification will be used. If areas occur unclassified go back and set more ROIs. In the classification of this tutorial, the Minimum Distance Algorithm came out as the best classification algorithm.


Classification.JPG


Check MC ID to use the macro classes and uncheck LCS. Click run and safe the classification in your desired directory.


The output can be look like this:


Output classification.JPG


Assessing the classification

You can assess the classification easily with you eyes. You can move the classification Layer above the Virtual band Set 1. Zoom into the picture and focus on an object. Checking and unchecking the classification layer allows you to verify the classes.


Classification aboveLayer2.JPG Truecolours2.JPG


As you see, it is difficult for the program to distinguish between unused fields and buildings. The following picture explains why:


Signature2.JPG