1

I am a new Google Earth Engine user. I have tried to remove clouds and cloud shadows using pixel_qa band. However, sometimes the cloud masking makes tidal flat or coastline to remove. I don't know why it happens.

How can I remove only clouds, not coastline and tidal flat? Besides using pixel_qa band, is there another way to remove clouds?

Code:

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 image.updateMask(mask);
}

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterDate('2016-05-01', '2016-05-31')
                  .filterMetadata('WRS_PATH', 'equals', 116)
                  .filterMetadata('WRS_ROW', 'equals', 34)
                  .map(maskL8sr);

Map.addLayer(dataset)                  

1 Answer 1

2

If you want to use the pixel_qa band, you could allow for low-confidence cloud pixels. Of course, it will not be as efficient at at masking real clouds.

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');
  var notMediumHighCloudConfidence = qa.bitwiseAnd(1 << 6).neq(0)

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

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

Alternatively, TOA's BQA band is a bit less aggressive.

function maskL8toa(image) {
  // Get the pixel QA band.
  var qa = image.select('BQA');

  var badPixels = qa.bitwiseAnd(15).not()
  var cloud = qa.bitwiseAnd(16).not()  
  var shadow = qa.bitwiseAnd(256).not()  
  var cirrus = qa.bitwiseAnd(4096).not()  

  var mask = badPixels
    .and(cloud)
    .and(shadow)
    .and(cirrus)

  return image
    .updateMask(mask);
}

https://code.earthengine.google.com/118de0b89b417d327fe17fe6fb406a71

In both cases, there are pixels incorrectly removed due to the shadow masking. If you're find with having cloud shadows, that'd be one way to ensure you don't loose that data.

Finally, you could skip the QA band altogether and use some cloud-scoring algorithm, like the one described in the docs: https://developers.google.com/earth-engine/landsat#simple-cloud-score

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.