I have an image collection of Landsat 5, Landsat 7 and Landsat 8 images. I want to calculate the median value of my image collection. Before that I want to exclude all cloudy pixels of my collection, so that they are not considered to calculate the median.

The standard function maskL8sr(image) doesn't seem to work. It shows for my median value image clouds inside the image as shown in my images.

First Image: Single Landsat 8 image of the month October

Second Image: Median value of image collection for the month's May till October

Single Landsat 8 image of the month October

Median value of image collection for the month's May till October

My code looks so far like this:

var geoshape = ee.FeatureCollection('ROI');

var col5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_SR").select(['B1','B2','B3','B4','B5','B7','pixel_qa']);

var col7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_SR").select(['B1','B2','B3','B4','B5','B7','pixel_qa']);

var col8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").select(['B2','B3','B4','B5','B6','B7','pixel_qa'],['B1','B2','B3','B4','B5','B7','pixel_qa']);

var col57 = col5.merge(col7);
var col = col5.merge(col8);

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

var dataset = ee.ImageCollection(col)
          .filterDate('2016-05-01', '2016-10-31')
          .filter(ee.Filter.eq('WRS_ROW', 52))
          .filter(ee.Filter.lt('CLOUD_COVER', 25))

var medianpixels = dataset.mean();
var medianpixelsclipped = medianpixels.clip(geoshape);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.