Link Search Menu Expand Document

Tutorial 9

Cloud detection and removal

// Load a cloudy Landsat scene and display it.
var cloudy_scene = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');
Map.centerObject(cloudy_scene);
Map.addLayer(cloudy_scene, {bands: ['B4', 'B3', 'B2'], max: 0.4}, 'TOA');

/* Add the cloud score band, which is automatically called 'cloud'. The simpleCloudScore function 
uses brightness, temperature, and NDSI to compute a score in the range [0,100]. */
var scored = ee.Algorithms.Landsat.simpleCloudScore(cloudy_scene);

/* Create a mask from the cloud score by experimentally selecting a threshold. Smaller thresholds  
mean more pixels are selected as clouds. */
var mask50 = scored.select(['cloud']).lte(50); // selects pixels with cloud score of 50 or less
var mask30 = scored.select(['cloud']).lte(30);

// Apply the masks created above to the image and display the result to determine an appropriate threshold. 
var masked50 = cloudy_scene.updateMask(mask50); //apply mask50
Map.addLayer(masked50, {bands: ['B4', 'B3', 'B2'], max: 0.4}, 'masked50');
var masked30 = cloudy_scene.updateMask(mask30); //apply mask30
Map.addLayer(masked30, {bands: ['B4', 'B3', 'B2'], max: 0.4}, 'masked30');