1

I'm trying to create a cloud free S2 Image. Now this code works, but I want to add a buffer of 20 or 30 meters around the cloud mask, because there still is the edge of the clouds in my image. [![Example image][1]][1]

 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
 */



function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

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

  return image.updateMask(mask).divide(10000);
}

// Map the function over one year of data and take the median.
// Load Sentinel-2 TOA reflectance data.
var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterDate('2019-07-01', '2019-07-30')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 9))
                  .map(maskS2clouds);

var medianpixels = dataset.median()
var medianclipped = medianpixels.clip(geometry)

Map.addLayer(medianclipped,{
  min: 0.0,
  max: 0.3,
  gamma: 1.7,
  bands: ['B4', 'B3', 'B2'], }) ```


  [1]: https://i.stack.imgur.com/HruSG.png
Max
  • 45
  • 3
  • 1
    A similar question was answered on GIS stack exchange: [https://gis.stackexchange.com/questions/360265/earth-engine-buffer-cloud-mask](https://gis.stackexchange.com/questions/360265/earth-engine-buffer-cloud-mask) – cengstro Jun 22 '20 at 23:00

0 Answers0