[GIS] Mask clouds in an ImageCollection google earth engine

google-earth-enginelandsatndvi

Is It possible to create .median() Surface Refletance image (landSat 8 RS) without clouds before calculating the NDVI in goolge earth engine? I need to work with a year (eg. 2016-01-01, 2016-12-31), so I need to remove the clouds to create a single image free of clouds and then calculate the NDVI.

Best Answer

Based on the answer of Mask clouds in LandSat 8 surface refletance image, one possibility is:

NOTE: replace YOUR_PLACE with a Geometry or Feature

// Filter the collection
var col = ee.ImageCollection("LANDSAT/LC8_SR")
          .filterDate("2016-01-01", "2016-12-31")
          .filterBounds(YOUR_PLACE)

// Mask clouds
var col_noclouds = col.map(function(img) {
                   var mask = img.select(['cfmask']).neq(4)
                   return img.updateMask(mask)
                   })

// Median image
var median = ee.Image(col_noclouds.median())

// NDVI
var median_ndvi = median.normalizedDifference(['B4', 'B5'])
Related Question