Sentinel-2 data currently has two products in GEE: one is ordinary data without atmospheric correction; the other is data after atmospheric correction (incomplete). Both of these methods of data de-clouding are accomplished through the QA band.
code
var roi = /* color: #0b4a8b */ee.Geometry.Polygon(
[[[115.22447911987308, 38.97207826950874],
[117.64147130737308, 39.07450027191289],
[117.55358068237308, 40.67633196985795],
[114.91686193237308, 40.576272152256934]]]);
Map.centerObject(roi, 7);
//利用Sentinel-2自带的质量波段QA60通过按位运算去除云或阴影
function rmCloud(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
var rawImage = ee.Image("COPERNICUS/S2/20180118T031039_20180118T031037_T50SMJ");
var visParams = {
bands: ['B4', 'B3', 'B2'],
min: 0,
max: 3000
};
print("rawImage", rawImage);
Map.addLayer(rawImage, visParams, "rawImage");
var cleanImage = rmCloud(rawImage);
print("cleanImage", cleanImage);
Map.addLayer(cleanImage, visParams, "cleanImage");
result