I would like to know how to remove the clouds in a ImageCollection of LandSat 8 Surface Reflectance (SR) image and create a single image without clouds using google earth engine, to calculate NDVI. I wore a javaScrit code to remove clouds in Landsat 8 TOA Reflectance, but it doesn't work for SR imagens...


1 Answer 1


The Surface Reflectance products contain a band called 'cfmask' and 'cfmask_conf'. The documentation tells you that all pixels labelled 4 in the first band are clouds. If you just want to mask clouds from your NDVI calculation you just have to update the image mask. If you want to do an ImageCollection you simply have to .map it as a function.

An example image from the alps with only clouds masked from the NDVI as well as an NDVI time-series from the region. The great thing about the EarthEngine is that instead of the NDVI mean you can also look at the NDVI time-series for selected areas.

// single image
var lt8 = ee.Image('LANDSAT/LC8_SR/LC81930272016103')

var lt8_ndvi = lt8
  .normalizedDifference(['B4', 'B5'])  // calculate NDVI
  .updateMask(lt8.select(['cfmask']).neq(4))  // mask everything labeled 'cloud'

// Map.centerObject(lt8_ndvi, 10)
Map.addLayer(lt8_ndvi, {}, "LC81930272016103 NDVI cloud masked", 0)

// image collection
var lt8_ic = ee.ImageCollection('LANDSAT/LC8_SR')
  .filterBounds(aoi)  // filter to area-of-interest
  .filterDate(ee.Date("2016-01-01"),ee.Date("2016-12-31"))  // filter to 2016

var lt8_ndvi_ic = lt8_ic
  .map(function(img){  // add cloud free NDVI to all images
  return img.addBands(img.normalizedDifference(['B4', 'B5'])).updateMask(img.select(['cfmask']).neq(4))


Map.centerObject(testPoint, 10)
var ndvi_viz = {min:-0.8, max:0.3, palette:'000000,00FF00'};
Map.addLayer(lt8_ndvi_ic.select('nd').mean(), ndvi_viz, "LT8 2016 NDVI mean")

// NDVI time-series chart
// Create and print the chart.
print(ui.Chart.image.series(lt8_ndvi_ic.select('nd'), testPoint, ee.Reducer.mean(), 30));
  • 1
    Nice answer. I only discovered GEE recently, having done an MSc involving remote sensing nearly 20 years ago, but not used it since. It really is a game changer for introducing people to remote sensing and quick model building and investigation. Commented May 27, 2017 at 16:54
  • Thank you for the answer, is It possible to create .median() image without clouds before calculating the NDVI? I need to work with a year (eg. 2016-01-01, 2016-12-31), so I need to remove the clouds to create a sigle image free of clouds and then calculate the NDVI. Commented May 28, 2017 at 0:17
  • @UilsonRicardo I included an example for the NDVI mean for a full year with cloud masking.
    – Kersten
    Commented May 31, 2017 at 13:43

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.