0

I want to remove clouds from the collection of images and replace new values with pixels of clouds. I have written code, but it's not working.

Here is my code:

var table = ee.FeatureCollection("users/nadiajabeen/chitral");

//---------Image Collection Landsat8---------------
var image=ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2020-08-01','2020-08-17')
.filterBounds(table)
.sort('CLOUD_COVER', false);
Map.setCenter(72.04589459686508,36.6838680049941,7)
print(image)
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 mosaicfree = maskClouds(image);

1 Answer 1

0

You can try and change this:

pixel_qa >> 
QA_PIXEL

return getQABits(QA, 3,3, 'Cloud_shadows').eq(0); >>
return getQABits(QA, 3,4, 'Cloud_shadows').eq(0);

return getQABits(QA, 5,5, 'Cloud').eq(0); >>
return getQABits(QA, 10,11, 'Cloud').eq(1);

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.