I am new in GEE, and tried to run a simple code to mask cloud pixels. However when I added the image selected with my filters I saw that the result of the cloud filter are empty areas, as shown below:

enter image description here I thought if I used the Mean function var scene = ee.Image (collection1.sort 'CLOUD_COVER') all empty pixels would be filled with the mean value of all others images.

A part of my code is:

var startDate = ee.Date('2018-01-01'); 
var endDate = ee.Date('2018-12-31'); 

var fDeleteClouds = function(image) { var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']);
                                return image.updateMask(cloud.lt(30))};

var collection1 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') 

var scene = ee.Image(collection1.sort('CLOUD_COVER').mean()); 

var vizParams = {bands: ['B4', 'B3', 'B2']};

Map.addLayer(scene, vizParams,'Imagem_selecionada');

Any ideas how I can fix it and fill empty pixels with the mean of the neighborhood pixels?

I need a full image after the filter to run a unsupervised classification with it.


The mask IS working correctly as it is simply removing the pixels that have cloud score greater than or equal to the value you specified i.e. 30. It simply means that all the images in the image collection had cloud score above 30 at that pixel.

If you want to fill the holes by using the mean of neighborhood pixels then you can use the function focal_mean. Here the radius is the number of pixels from the actual pixel that you want to calculate mean from

mean_scene = scene.focal_mean({

Note that when you add the layer to the map it computes at you current view scale and not the actual layer's scale. So, if you want to visualize the computation happening on the dataset's scale then it is a good idea to reproject the layer before adding it to the map

Map.addLayer(mean_scene.reproject({crs:'EPSG:4326', scale:30}));

Finally, if you want to preserve the original pixels from the scene and fill only the empty pixels with the focal means, you can unmask the scene with the mean scene

scene = scene.unmask(mean_scene)

Edit: If your scenes still has empty pixels after this, you can either increase the radius or do the focal_mean again so that the new holes are filled with mean of the new pixels that were computed.

  • Thank you for your help. It works perfectly.
    – DEA
    Jun 11 '19 at 17:32
  • Awesome! It would be great if you could accept the answer if that worked for you! Jun 12 '19 at 4:16
  • Do you have any ideia how to solve this problem? gis.stackexchange.com/questions/325494/…
    – DEA
    Jun 12 '19 at 17:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.