I am creating a Sentinel-2 median composite in Google Earth Engine using the following scripts:
How to achieve a more natural-looking and sharper Cloudless Sentinel-2 composite in GEE?
I am generating Sentinel-2 composites in Google Earth Engine using either of the following scripts:
Script A:
// STEP 1: Define ROI & Season
var roi = ee.Geometry.Rectangle([76.84, 28.40, 77.35, 28.88]);
var startDate = '2023-06-01';
var endDate = '2024-08-31';
// STEP 2: Load and Filter Sentinel-2
var s2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(roi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.select(['B4', 'B3', 'B2', 'SCL']);
// STEP 3: Cloud/Shadow Mask
function maskClouds(image) {
var scl = image.select('SCL');
var cloudShadow = scl.eq(3);
var cloudsMed = scl.eq(8);
var cloudsHigh = scl.eq(9);
var cirrus = scl.eq(10);
var mask = cloudShadow.or(cloudsMed).or(cloudsHigh).or(cirrus);
return image.updateMask(mask.not());
}
var composite = s2.map(maskClouds).median();
// STEP 4: Visualization
Map.centerObject(roi, 10);
Map.addLayer(composite, {
bands: ['B4','B3','B2'],
min: 0,
max: 3000,
gamma: 1.2
}, 'Cloud-Free Sentinel-2');
// STEP 5: Export
Export.image.toDrive({
image: composite,
description: 'Sentinel2_India_Delhi_Improved',
folder: 'Sentinel2_Exports',
scale: 10,
region: roi,
fileFormat: 'GeoTIFF',
maxPixels: 1e13
});
Script B:
// STEP 1: Define ROI & Season
var roi = ee.Geometry.Rectangle([76.84, 28.40, 77.35, 28.88]);
var startDate = '2023-06-01';
var endDate = '2024-08-31';
// STEP 2: Load and Filter Sentinel-2
var s2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(roi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.select(['B4', 'B3', 'B2', 'SCL']);
// STEP 3: Simple Cloud Mask
function maskClouds(image) {
var cloudProb = image.select('SCL').eq(9);
return image.updateMask(cloudProb.not());
}
var composite = s2.map(maskClouds).median();
// STEP 4: Visualization
Map.centerObject(roi, 10);
Map.addLayer(composite, {
min: 500,
max: 7000,
bands: ['B4', 'B3', 'B2']
}, 'Cloud-Free Sentinel-2');
// STEP 5: Export
Export.image.toDrive({
image: composite,
description: 'Sentinel2_India_Delhi500_700',
folder: 'Sentinel2_Exports',
scale: 10,
region: roi,
fileFormat: 'GeoTIFF',
maxPixels: 1e13
});
In both scripts, the composite always looks too saturated, unnatural, or not sharp. I’ve tried adjusting the min, max, and gamma values, but it still comes out oversaturated or lacking natural color. How can I better scale or stretch the pixel values (or otherwise process the composite) so it appears more true-to-life in Google Earth Engine? A nice looking satellite photo?
Field on the right should be green
Thanks!!