I am trying to make a cloud-free landsat composite in Google Earth Engine in an area with a lot of clouds (Indonesian cloud-forest). Previously, I accomplished this successfully by making a greenest pixel composite, in which I used the pixel with the highest NDVI value to make sure I was using non-cloud pixels in my composite image.
//Filter landsat 8 image collection by date, area
var collection = landsat
.filterBounds(bounds)
.filterDate(2016-08-01, 2016-10-31);
// Sort from least to most cloudy and get first (least cloudy) image
var sorted = collection.sort('CLOUD_COVER');
var image = ee.Image(sorted.first());
//Function to get NDVI
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
//Add NDVI bands to image collection
var withNDVI = landsat.map(addNDVI);
// Make a "greenest" pixel composite using NDVI
var greenest = withNDVI.qualityMosaic('NDVI');
Map.addLayer(greenest, {bands: ['B4', 'B3', 'B2'], max: 0.15}, 'greenest');
The code works fine, however, I am concerned using the highest NDVI pixels to make my composite is over-representing forested area. Therefore, I am looking for a method to extract the pixels with the highest NDVI (to get rid of the clouds), and then using all 7 other bands of that pixel in my composite (instead of using the NDVI band itself). My questions are: would this even get rid of forest over-representation, or would I still have the same problem? Second, if this method does seem like a legitimate way to get rid clouds while making a composite that does not over-represent forest, how can I extract pixels of a high NDVI, and then use their other bands to make a composite?