Video Tutorial: Using the tool Band calc of the Semi-Automatic Classification Plugin

This is a tutorial about the use of the tool Band calc that allows for the raster calculation for bands. In particular, we are going to calculate the NDVI (Normalized Difference Vegetation Index) of a Landsat image, and then apply a condition in order to refine a land cover classification (see Tutorial 2: Land Cover Classification of Landsat Images ) basing on NDVI values (a sort of Decision Tree Classifier).

The Band calc can perform multiple calculations in sequence. We are going to apply a mask to every Landsat bands in order to exclude cirrus and cloud pixels from the NDVI calculation, and avoid anomalous values. In particular, Landsat 8 includes a Quality Assessment Band ) that can be used for masking cirrus and cloud pixels.

In particular, the Quality Assessment Band of the sample dataset includes mainly the value 53248 indicating clouds. Therefore, in this tutorial we are going to exclude the pixels with the value 53248 from all the Landsat bands.

TIP : If the text in Expression is green it means that the syntax is correct, otherwise it is red and the button Calculate is disabled.

Click the button Calculate, select where to save the bands (e.g. a new directory named masked_bands) and write the output name (e.g. masked). Multiple outputs are created with the same output name and a numerical suffix based on the numerical order of the expressions. Calculated bands are also added to QGIS.

Masked bands

According to the order of expressions, the file masked_1 corresponds to the band RT_LC81910312015006LGN00_B2, the file masked_2 corresponds to the band RT_LC81910312015006LGN00_B3, and so on. Masked pixels have NoData values (i.e. nan).

NDVI Calculation

NDVI is an index calculated as (NearInfraredband-Redband)/(NearInfraredband+Redband) which ranges from -1 to 1 . Green vegetation has the highest NDVI values tending to 1.

Open the Band calc and click the button Refresh list. Clear the content of Expression and write the following expression for the calculation of NDVI:

("masked_4.tif"-"masked_3.tif")/("masked_4.tif"+"masked_3.tif")

where masked_4.tif is the Near Infrared band and masked_3.tif is the Red band.

The expression in Band calc

TIP : The expression can work both with Variable and Bandname between quotes. Also, bands in the Band set can be referenced directly; for example bandset#b1 refers to band 1 of the Band set. Double click on any item in the Band list for adding its name to the expression.

Click the button Calculate, select where to save the NDVI (e.g. a new file named NDVI). The NDVI is added to QGIS.

We are going to refine this classification defining the following condition: pixels having NDVI > 0.5 are classified Vegetation. The value 0.5 is an arbitrary value that should be changed according to the image condition (i.e. phenological state of vegetation).

Open the Band calc and click the button Refresh list. Clear the content of Expression and write the following expression:

np.where("NDVI.tif">0.5,3,"classification")

which means that if NDVI value is greater than 0.5, assign the pixel value 3 (i.e. Vegetation), otherwise leave the original classification value.

The expression in Band calc

Click the button Calculate, select where to save the new classification (e.g. a new file named refined_classification). The new classification is added to QGIS.

The output land cover classification

It is possible to copy the style from the original classification (in QGIS Layers right click on the layer name and select Copystyle) and paste it to the new classification (right click on the layer name and select Pastestyle).

The output land cover classification with color style

You can see that now a larger area is classified as vegetation.

Please, remember that a Facebook group and a Google+ Community are available for sharing information and asking for help about the Semi-Automatic Classification Plugin.