Application of masks for clouds in Landsat 8 images with QGIS

In this opportunity we are going to present Cloud Masking, a QGIS plugin with which we can mask clouds, cloud shadows, cirrus (grey clouds), aerosols, ice/snow and water for Landsat products (4, 5, 7 and 8), using different processes and filters such as Fmask, Blue Band, Cloud QA, Aerosol and Pixel QA.

Data source

For this procedure we are going to consider a scene from Landsat 8, which can be downloaded from different sources, in this case it was done from: https://earthexplorer.usgs.gov/. The area of interest corresponds to Path/Row 8/64.

Download Landsat bands with ESPA

In order to achieve better results for masking processing and filter application, other Landsat products or bands are required, which must be requested through the Earth Resources Observation and Science (Eros) Center Science Processig Architecture (ESPA) interface, for which it is necessary to have an account.

With our registration data, we will access a page that asks us to indicate as a first step the list of scenes, in this case Landsat 8, for it we must generate a text file (*.txt), with the codes that identify the scenes, for our case would be something like the following figure.

Now when we are asked for the list of scenes, we simply have to indicate the location of our text file. For the other options, consider those indicated in the figure below, where for this case was also requested in the output configuration section, that our scenes be saved as GeoTiff and have a UTM Zone 18S projection.

After placing the order, we will receive an email announcing that the link for the download is ready and we can already download our entire order.

Cloud Masking Plugin

Once we have our required bands, our next step is to install and then activate the Cloud Masking plugin. As shown in the figure below, a panel of the plugin is generated.

The present plugin is divided and ordered in three sections; (1) Open and Load, from where we can open the metadata file (MTL) and the stacked bands, (2) Filters and Mask, which allows us to enable and configure the filters to apply the cloud mask and (3) Apply and Save, to save the created mask and apply it over the stacked bands.

Opening Metadata

The first thing we have to do with the plugin is to locate the metadata file of our scene (MTL), to open it and identify our bands.

Opening a Stack of Bands

It is not a mandatory step, but it is recommended to make a combination of RGB bands, in order to be able to visualize and review the scene. On the right side we can see that there are buttons with the most common combinations. For this case we will choose “False Color”, then we click on “Load stack”, with it we will be able to appreciate in our map view, the combination of bands established.

Selecting the filters to be applied

Now in the next section we must select our filters. The plugin has four different filters to apply, Fmask and Blue Band are available for any Landsat scene, but Aerosol and Pixel QA (for the case of Landsat 8), are available only for scenes that are requested through ESPA, as we saw earlier. You can activate more than one filter at a time, the plug-in accumulates the filters in the same order (from bottom to top).

FMask Filter

The first filter that we will activate will be the FMask, leaving the default options. The Fmask process uses an implementation of a python algorithm called fmask, described in http://pythonfmask.org/en/latest/, acting as an internal library in the plugin.

Blue Band Filter

This filter uses the blue band of the Landsat (Band 2 for Landsat 8) to mask all pixels with values below the set threshold, the latter also depends on the version used, therefore for Landsat 8 the threshold is 0-65534 (16 bits).

Aerosol Filter

This type of filter can only be executed in Landsat 8 scenes, for which an 8-bit (Aerosol) band is used. When we review the files requested through ESPA, we will see that there is a band that has the ending *_sr_aerosol.tif. These 8 bits are:

The plug-in implements this bit-by-bit filter (only the useful bits) and can enable one or more bits.

For more information, it is important to consult this product guide.

QA Pixel Filter

To use this filter, we must have a 16-bit band, the same that has the termination *_pixel_qa.tif. This file will only be available when we select in our order through ESPA, the option “Surface Reflectance (SR)”, which represents a special collection of Landsat. These 16 bits for Landsat 8 are:

The options of the Pixel QA to use are:

Generating the cloud mask

From here we can generate the masks according to the filters previously enabled. There are three options for its generation:

  1. The Whole Image, which comes by default, this happens if the other options are disabled;
  2. Only in the selected area, when this option is selected, we can process the mask in a specific area of the image, which can be selected in the map view (only a rectangular area). If the Keep the original image size option is enabled, the result mask will have the same extension, otherwise, the result mask will be cropped in the selected area;
  3. The In only shape area option, with this option, you can process the mask only inside a particular Shape, the same that must be created before applying. If the option Delete data out of shape is enabled, the resulting mask will have the same extension but the data out of the shape will be masked, otherwise the resulting mask will have the same and the data out of shape will be valid (only masked inside the shape).

In our case we are going to use option 2 and then click on “Generate mask”.

If we look at our layers panel, we’ll see that a temporary layer was generated with the result of the mask generated by applying the enabled filters.

Applying the mask

The plugin helps us to create, apply and save the bands stacked with the loaded Landsat, having three options to apply the mask on the stacked bands.

  1. Raw Bands, which are the original bands of landsat products, one can select the stacking order oneself, by default they are the reflectance bands;
  2. SR Bands, these are the Landsat products obtained by ESPA, Surface Reflectance (SR), this option is only enabled if you are processing this type of product, and you can also select the order of the bands to be stacked, by default are the reflectance bands;
  3. Particular file, this last option applies to a particular stack or image file.

For our case we will use option 2 and then indicate the location where our image will be stored stacked with the mask applied.

Finally when the mask is executed, we can make a combination of bands and to verify our result we can use the plugin “Value Tool”, and if we are located in an area where there are clouds and a mask was applied, we will check that the values are “zero”.

It is recommended to save the initial temporary layer with the filters applied, so it is important to save the style of the layer so that we can add it in another project.

Translated from: carbajallosa

Discover more from GIS Crack

Subscribe now to keep reading and get access to the full archive.

Continue reading