I'm trying to train an algorithm to detect mangrove forests in several regions around Asia for each year using Landsat 8. When I apply the .median reducer on some image collections over a 1-year timespan, the composite is totally clear and cloud free (see 1st image - code link: https://code.earthengine.google.com/486067b4ca23929c45313eadd0e0cacc)
However, for some regions or years with high cloud cover throughout the year, the .median reduction gives me a composite that is noisy (see 2nd image - code link: https://code.earthengine.google.com/286e97966b48d2ae426b832f024097ee).
Is there a way I can apply the .median reducer only on images with comparatively low cloud cover? Or can anyone here think of another way of getting an accurate, cloud-free, year-long composite for an image collection to do a supervised classification?
Code:
// filtering the image collection
var image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.select(['B[1-7]'])
.filterBounds(roi)
.filterDate('2015-01-01', '2015-12-31')
.median());
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'landsat');
// // merge feature collections
// var newfc = mangrove.merge(other_veg).merge(water).merge(urban);
// print(newfc);
// // create training data
// var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
// var training = image.select(bands).sampleRegions({
// collection: newfc,
// properties: ['landcover'],
// scale: 30
// });
// print(training);
// //Train the classifier
// var classifier = ee.Classifier.cart().train({
// features: training,
// classProperty: 'landcover',
// inputProperties: bands
// });
// //Run the classification
// var classified = image.select(bands).classify(classifier);
// //Display classification
// Map.centerObject(newfc, 11);
// Map.addLayer(image,
// {bands: ['B4', 'B3', 'B2'], max: 0.3},
// 'Landsat image');
// Map.addLayer(classified,
// {min: 0, max: 3, palette: ['008b04', 'ffc82d', 'ff0000', '1400c2']},
// 'classification');
// Map.addLayer(newfc, {}, 'data_points');
https://code.earthengine.google.com/e03d657c9b91c43056f51a175f0a0ff2