ee.ImageCollection.qualityMosaic()
- Mosaic obtains the last pixel with value, and then generates an image;
- qualityMosaic extracts the maximum value of the pixel, similar to using the max function for the collection. It can have the effect of cloud removal when processing NDVI;
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA");
var l8_select=l8.filterBounds(ee.Geometry.Point(106.5,29.6))
.filterDate("2018-01-01","2018-12-31")
.select("B[3,4,5]")
function add_NDVI(image){
var NDVI=image.normalizedDifference(["B5","B4"]).rename("NDVI")
return image.addBands(NDVI)
}
var l8_ndvi=l8_select.map(add_NDVI)
var ndvi_quality=l8_ndvi.qualityMosaic("NDVI")
Map.setCenter(106.7,29.7,7)
Map.addLayer(l8_ndvi,{"bands":["B5","B4","B3"],"max":0.5},"l8_ndvi")
Map.addLayer(ndvi_quality,{"bands":["B5","B4","B3"],"max":0.5},"ndvi_quality")
print(l8_ndvi,ndvi_quality)
qualityMosaic() handles NDVI to go to the cloud
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA");
var l8_select=l8.filterBounds(ee.Geometry.Point(106.5,29.6))
.filterDate("2018-01-01","2018-12-31")
.select("B[3,4,5]")
function add_NDVI(image){
var NDVI=image.normalizedDifference(["B5","B4"]).rename("NDVI")
return image.addBands(NDVI)
}
var l8_ndvi=l8_select.map(add_NDVI)
var ndvi_quality=l8_ndvi.qualityMosaic("NDVI").select("NDVI")
Map.setCenter(106.7,29.7,9)
Map.addLayer(ndvi_quality,{"min":-1,"max":1,"palette":'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'},"ndvi_quality")
simpleCloudScore()
To be studied
simpleComposite()
Take the raster value with the smallest cloud content in the image set as the selected value, and then stitch all the selected values into an image
Return an Image that went to the cloud
Note: Need row data in landsat
var sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan"),
l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1");
var l8_select=l8.filterBounds(sichuan)
.filterDate("2018-01-01","2018-12-31")
var img_simpleComposite=ee.Algorithms.Landsat.simpleComposite({collection:l8_select,asFloat:true}).clip(sichuan)
print("img_simpleComposite",img_simpleComposite)
Map.centerObject(sichuan,6)
Map.addLayer(img_simpleComposite,{bands:["B5","B4","B3"],max:0.3},"B543")
Map.addLayer(img_simpleComposite,{bands:["B4","B3","B2"],max:0.3},"B432")
Custom function to cloud
Go to the cloud for each image in the image set, and return an image set that has gone to the cloud
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR"),
sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
var imgs = l8.filterBounds(sichuan)
.filterDate("2018-1-1", "2019-1-1")
.map(rmCloud)
.map(scaleImage)
var l8Image = imgs.median().clip(sichuan)
print("l8Image",l8Image)
Map.centerObject(sichuan, 7);
Map.addLayer(l8Image, {min: 0,max: 0.3,bands: ["B4", "B3", "B2"]}, "l8Image");
//Landsat8 SR数据去云
function rmCloud(image) {
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
var qa = image.select("pixel_qa");
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return image.updateMask(mask);
}
function scaleImage(image) {
var time_start = image.get("system:time_start");
return image.multiply(0.0001).set("system:time_start", time_start);
}
or
var sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
var maskL8 = function(image) {
var qa = image.select('BQA');
var mask = qa.bitwiseAnd(1 << 4).eq(0);
return image.updateMask(mask);
}
var composite = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate('2018-01-01', '2019-1-1')
.map(maskL8)
.median();
Map.addLayer(composite.clip(sichuan), {bands: ['B4', 'B3', 'B2'], max: 0.3});
Map.centerObject(sichuan,6)