Mask clouds using the QA band

step 1: import the image

// import the image
var image = ee.Image("LANDSAT/LC08/C01/T1_SR/LC08_141055_20170113");

step 2: select the qa band to get the cloud and shadow mask

// get QA band
var QA = image.select("pixel_qa");
var shadow = QA.bitwiseAnd(8).neq(0);
var cloud = QA.bitwiseAnd(32).neq(0);

step 3: mask the clouds

// mask image
var cloudMaskedImg = image.updateMask(shadow.not()).updateMask(cloud.not());

step 4: display the image

// add layers
Map.addLayer(image,{min:0,max:3000,bands:"??"},"original image");
Map.addLayer(shadow,{min:0,max:??},"shadow mask");
Map.addLayer(cloud,{min:0,max:??},"cloud mask");
Map.addLayer(cloudMaskedImg,{min:0,max:3000,bands:"??"},"masked image");

 

link

 

Advertisements