Unsupervised Classification using the Semi-Automatic Classification Plugin version 7

This is a basic tutorial about the use of Semi-Automatic Classification Plugin (SCP) for the unsupervised classification of a multispectral image. It is recommended to read the Brief Introduction to Remote Sensing before this tutorial, and in particular the part Clustering.

Clustering can be used for unsupervised classification, which means that no training input is required, producing classes (i.e. clusters) that have no definition and consequently the user must assign a land cover label to each class.

The purpose of the classification is to identify the land cover classes with the corresponding ID codes defined in the following table.

Classes
Class nameClass ID
Water1
Built-up2
Vegetation3
Soil4


The following are the main steps of this tutorial:
  1. Input Data
  2. Clustering
  3. Reclassification of the output
  4. Refinement of the output

Following the video of this tutorial.



1. Input Data

Any multispectral image can be used for unsupervised classification. In this tutorial, we are going to use a subset of a Sentinel-2 Satellite image (Copernicus land monitoring services) and use the bands illustrated in the following table. You can download the image from this archive (about 30 MB, © Copernicus Sentinel data 2020 downloaded from https://scihub.copernicus.eu/), and then unzip the downloaded file.

Sentinel-2 BandsCentral Wavelength [micrometers]Resolution [meters]
Band 2 - Blue0.49010
Band 3 - Green0.56010
Band 4 - Red0.66510
Band 5 - Vegetation Red Edge0.70520
Band 6 - Vegetation Red Edge0.74020
Band 7 - Vegetation Red Edge0.78320
Band 8 - NIR0.84210
Band 8A - Vegetation Red Edge0.86520
Band 11 - SWIR1.61020
Band 12 - SWIR2.19020

Start QGIS and the SCP.

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. In order to convert bands to reflectance, open the Preprocessing clicking the button in the SCP menu or the SCP dock, and select the tab Sentinel-2.

Click the button Directory containing Sentinel-2 bands and select the directory of 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.

Check the option Create Band set and use Band set tools in order to create automatically the input Band set that will be used for clustering.

To start the conversion process, click the button RUN and select the directory where converted bands are saved. After a few minutes, converted bands are loaded and displayed (file name beginning with RT_).


Converted bands


Open the tab Band set clicking the button in the SCP menu or the SCP dock. The bands are already listed in the first Band set.


Band set


2. Clustering

Clustering requires the user to define the number of clusters (i.e. classes) expected in the image, which correspond to as many spectral signatures (i.e. seeds). During the first iteration clusters are produced calculating the pixel spectral distance with initial spectral signatures. Pixels are assigned according to the most similar spectral signature, therefore producing clusters. In this tutorial we are going to perform clustering using the ISODATA algorithm, which includes steps for merging clusters having similar spectral signatures and splitting clusters having too high variability. We are going to select randomly the starting spectral signatures and use the algorithm Euclidean Distance for distance calculation.

Open the tab Clustering clicking the button in the SCP menu or the SCP dock. In Select input band set we set 1 because we are going to classify the first Band set.

In Method check ISODATA. In Distance threshold set 0.01, which is the distance required for merging clusters.

In Number of classes set 10; we set a number higher than the land cover classes defined at the beginning of this tutorial because we try to account for spectral variability of classes. In Max number of iterations set 10; in general, the more the iterations the better the result.

In ISODATA max standard deviation we set the maximum standard deviation considered for splitting a class; we can set the value 0.2 here. In ISODATA minimum class size in pixels we can set 10.

We check the option Use random seed signatures to randomly selects the spectral signatures of seed pixels from Band set. Now click the button RUN and define the path of the classification output.


Clustering tool


After the process, the result is displayed in the map. The result of the unsupervised classification is a raster having values that don’t correspond to the class IDs defined at the beginning of this tutorial. The number of classes can vary depending on the various iterations.


Result of clustering


The mean spectral signature of output classes is displayed in the panel. We could also save these spectral signatures in a previously created Training input if we wanted to use these in other supervised classifications.


3. Reclassification of the output

We must identify the correspondence between raster classes and the land cover class IDs defined at the beginning of this tutorial.

We can perform this task through photointerpretation. 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).


Color composite RGB=7-3-2


We should take note of the corresponding values, similarly to the following table as example. Please note that you should define different values according to the result of your classification output.

Class nameCluster IDNew class ID
Vegetation13
Built-up22
Vegetation33
Vegetation43
Vegetation53
Soil64
Soil74
Water81
Vegetation93
Soil104

Now we can reclassify the output raster according to out classification system.

Open the tool Reclassification clicking the button in the SCP menu or the SCP dock. Click Calculate unique values to automatically calculate unique values in the classification and fill the reclassification table. In New value set the corresponding New class ID.


Reclassification


When the table is complete, click the button RUN and define the path of the classification output. After the process, the raster is added to the map. We can define a symbology according to our classes.


Reclassified raster


Of course, the result of an unsupervised classification can have many classification errors. In this example, several pixels of soil have been classified as built-up. For reducing those errors we could repeat the clustering step increasing the Number of classes, reducing the value ISODATA max standard deviation, and increasing the value Distance threshold.


4. Refinement of the output

The classification could contain small patches of pixels that we would like to remove from the classification result.

We can use the tool Classification sieve to remove small patches of isolated pixel replacing them with the value of the largest neighbour patch. Open the tool Classification sieve clicking the button in the SCP menu or the SCP dock.

In Select the classification select the raster reclassified in the previous step (click the button to refresh the layer list if the classification is not listed). In Size threshold enter 2 to set the maximum size of the patch to be replaced (in pixel unit); all patches smaller than the selected number of pixels will be replaced by the value of the largest neighbour patch. Setting the value 2 we are going to remove isolated single pixels.


Sieve tool


In Pixel connection: select 8 as the type of pixel connection in a 3x3 window (i.e. diagonal pixels are considered connected). Now click the button RUN and define the path of the classification output. After the process, the raster is added to the map. We should see that single pixels have been replaced by the largest neighbour patch, resulting in a cleaner classification.


Refined classification


Well done! We have performed an unsupervised classification of a remote sensing image. We can improve the classification using some of the tools that will be described in other tutorials.


For any comment or question, join the Facebook group or GitHub discussions about the Semi-Automatic Classification Plugin.

Newer posts Older posts

Follow

RG