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.
The values that indicate with high confidence cirrus or clouds pixels are (for the description of these codes see the table at http://landsat.usgs.gov/L8QualityAssessmentBand.php ):
- 61440;
- 59424;
- 57344;
- 56320;
- 53248;
- 31744;
- 28672 .
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.
Following the video of this tutorial.
Following the video of this tutorial.
First, download the sample dataset, which is a Landsat 8 image already converted to reflectance (see Automatic Conversion to Surface Reflectance) from this link (data available from the U.S. Geological Survey). Also, download the land cover classification from here .
Application of a mask to multiple bands
Unzip the downloaded dataset and load all the raster bands in QGIS.
Open the Band calc and click the button
Refresh list
.
We are going to use conditional expressions (i.e.
np.where
, for more information see this page) with the following structure:
Where:
condition
is a logical condition between bands or values;value if true
andvalue if false
can be a numerical value, a band, or another expression.
In
Expression
enter the following block of expressions:
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.
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
( Near Infrared band - Red band ) / (Near Infrared band + Red band)
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:
where
masked_4.tif
is the Near Infrared band and masked_3.tif
is the Red band.
Click the button
Calculate
, select where to save the NDVI (e.g. a new file named NDVI). The NDVI is added to QGIS.Classification refinement basing on NDVI values
Load the downloaded classification in QGIS.
The classification is the result of Tutorial 2: Land Cover Classification of Landsat Images where the land cover classes described in the following table were identified.
Class name | Pixel value |
---|---|
Water | 1 |
Built-up | 2 |
Vegetation | 3 |
Bare soil | 4 |
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:
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.
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.
It is possible to copy the style from the original classification (in QGIS Layers right click on the layer name and select
Copy style
) and paste it to the new classification (right click on the layer name and select Paste 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.