2

I found some other posts asked the similar questions but in different tools like ArcGIS, GDAL, QGIS etc. What I want to ask is how to do this in GEE.

Now I have removed the bad observation pixels (like clouds and scan-line corrector-off gaps in southern Florida. But I found every tile has its own unique color scale. Particularly for the tile Path:16 Row:43 (the one locates at the southwestern corner which covers Key West) has a significant difference with other tiles, which results in a big error when I calculating and filtering the indices.

Here I attached the code and screenshot for your reference.

//Choose country using GEE Feature Collection

var region = ee.Geometry.Polygon({
  coords: [[[-82.48, 26.93], [-79.91, 26.93], [-79.97, 25.68], 
            [-80.78, 24.75], [-81.21, 25.07]]],
  geodesic: false
});


var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');

// Fmask classification values var FMASK_CLEAR_GROUND = 0; var FMASK_WATER = 2; var FMASK_CLOUD_SHADOW = 3; var FMASK_SNOW = 4; var FMASK_CLOUD = 5;

var non_mosaic = landsat8 .filterBounds(region) .filterDate('2017-01-01', '2017-12-31');

var getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    // Return a single band image of the extracted QA bits, giving the band
    // a new name.
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
};

// A function to mask out cloudy pixels.
var cloud_shadows = function(image) {
  // Select the QA band.
  var QA = image.select(['pixel_qa']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 3,3, 'Cloud_shadows').eq(0);
  // Return an image masking out cloudy areas.
};

// A function to mask out cloudy pixels.
var clouds = function(image) {
  // Select the QA band.
  var QA = image.select(['pixel_qa']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 5,5, 'Cloud').eq(0);
  // Return an image masking out cloudy areas.
};

var maskClouds = function(image) {
  var cs = cloud_shadows(image);
  var c = clouds(image);
  image = image.updateMask(cs);
  return image.updateMask(c);
};

var mosaic_free = non_mosaic.map(maskClouds).median();

var visParams = {bands: ['B4', 'B3', 'B2'],min: [0,0,0],max: [2000, 2000, 2000]};

Map.addLayer(mosaic_free, visParams, 'Cloud free'); 

enter image description here

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.