Using Landsat 8 Image To Perform Cloud Masking on GEE

Landsat 8 images are widely used for a variety of applications. However, cloud and cloud shadow cover issues are still a challenge. Clouds and cloud shadow decrease accuracy of remote sensing application results because they obscure the land surface, and the brightening effect of clouds and the darkening effect of cloud-shadow’s influence the reflectance capability of the target object. Cloud masking process solves the problem of cloud shadow. It is the process of identifying clouds from the satellite images and eliminating them so as to obtain a cloud free image. Cloud masking ensures that the pixels in the image are transparent and excluded from further analysis.

This article focuses on outlining the process of cloud masking step by step using Landsat 8 surface reflectance dataset in Google Earth Engine.

Select an Area of Interest.

You can choose an area of interest by importing a shapefile of the region you are interested in. To achieve this, proceed as follows:

  1. On the left side panel, click on Assets
  2. A list of your previously ingested tables (shapefiles) will appear
  3. Navigate to your shapefile of interest and click on the arrow to import the shapefile into the script.

Cloud Masking Function.

Write a function to mask the clouds from the pixel_qa band of Landsat 8 SR data.

function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = 1 << 3;
  var cloudsBitMask = 1 << 5;

  // Get the pixel QA band.
  var qa = image.select('pixel_qa');

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0));

  // Return the masked image, scaled to reflectance, without the QA bands.
  return image.updateMask(mask).divide(10000)
      .select("B[0-9]*")
      .copyProperties(image, ["system:time_start"]);
}

Apply the Function to Image Collection.

Map the function over one year of Landsat 8 SR data and apply a median reducer.

var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
    .filterDate('2016-01-01', '2016-12-31')
    .map(maskL8sr)
    
var composite = collection.median()

Display the Final Results.

Display the image before and after cloud masking and make a comparison between the two images.

Map.centerObject(table, 12)
Map.addLayer(collection, {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3}, 'original image');
Map.addLayer(composite, {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3}, 'cloud-masked image');

Original image

Cloud-masked Image

Link to full code:

https://code.earthengine.google.com/c7f0f3b1e7afc9c4d2a43e89ac9b766f

Previous Post
Next Post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.