Working with Sentinel-2 Imagery in GEE: Cloud Masking and Visualization

SHARE:

Learn how to use cloud masking and visualize Sentinel-2 imagery in Google Earth Engine. Includes scripts for RGB, NDVI, and true-color composites.

Sentinel-2 with cloud masking, developed by the European Space Agency (ESA), offers high-resolution multispectral imagery with a revisit time of just 5 days. It's one of the most popular datasets in Google Earth Engine (GEE) thanks to its 13 spectral bands, wide area coverage, and frequent updates.

But like most optical satellites, Sentinel-2 is affected by clouds, haze, and shadows, which can obscure land features. To get clean, usable imagery, cloud masking is a critical first step.

In this tutorial, you'll learn how to:

  • Load Sentinel-2 surface reflectance data

  • Mask clouds and cloud shadows using QA60 and SCL bands

  • Visualize imagery in true color, false color, and NDVI

Sentinel-2 imagery Cloud Masking and Visualization


1. Load Sentinel-2 SR Collection in GEE

We’ll use Level-2A (surface reflectance) data:
📦 Dataset ID: COPERNICUS/S2_SR


var region = ee.Geometry.Point([-71.9, 45.3]); // Sherbrooke, Canada var s2 = ee.ImageCollection('COPERNICUS/S2_SR') .filterDate('2023-01-01', '2023-01-31') .filterBounds(region) .sort('CLOUDY_PIXEL_PERCENTAGE');

2. Cloud Masking Using QA60 Band (Bitmask Method)

The QA60 band contains cloud and cirrus information encoded as bits.

Cloud Mask Function:


function maskS2clouds(image) { var qa = image.select('QA60'); var cloudBitMask = 1 << 10; // clouds var cirrusBitMask = 1 << 11; // cirrus var mask = qa.bitwiseAnd(cloudBitMask).eq(0) .and(qa.bitwiseAnd(cirrusBitMask).eq(0)); return image.updateMask(mask).copyProperties(image, ['system:time_start']); }

 Apply Cloud Mask:


var s2Clean = s2.map(maskS2clouds);

3. Alternative Cloud Masking Using SCL Band (Scene Classification)

SCL is available only in Level-2A products. This band classifies each pixel (e.g., cloud, vegetation, water).

 SCL-based Mask Function:


function sclMask(image) { var scl = image.select('SCL'); var cloudMask = scl.neq(3) // not cloud shadow .and(scl.neq(8)) // not cloud medium probability .and(scl.neq(9)) // not cloud high probability .and(scl.neq(10)); // not cirrus return image.updateMask(cloudMask).copyProperties(image, ['system:time_start']); }

 Apply:


var s2Masked = s2.map(sclMask);

SCL method is more flexible, especially for thematic classification.


4. Visualize Sentinel-2 in True Color

RGB (B4, B3, B2)


var rgb = s2Clean.median(); Map.centerObject(region, 10); Map.addLayer(rgb, {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000}, 'True Color');


5. Visualize Sentinel-2 in False Color (Vegetation Highlight)

NIR, Red, Green (B8, B4, B3)


Map.addLayer(rgb, {bands: ['B8', 'B4', 'B3'], min: 0, max: 3000}, 'False Color');

🌿 Healthy vegetation appears bright red.


6. Calculate and Visualize NDVI

NDVI is one of the most common vegetation indices, calculated as:

 (NIR - RED) / (NIR + RED)
For Sentinel-2: NIR = B8, RED = B4


var ndvi = rgb.normalizedDifference(['B8', 'B4']).rename('NDVI'); Map.addLayer(ndvi, {min: 0, max: 1, palette: ['white', 'green']}, 'NDVI');

📈 You can also chart NDVI over time or export it for further analysis.


7. Best Practices for Sentinel-2 Visualization

Tip Why It Matters
Use median() or mosaic() Reduces cloud impact
Apply cloud masking before calculations Ensures data integrity
Use scale = 10 when exporting Matches Sentinel-2 spatial resolution
Visualize with appropriate color palettes Enhances interpretability
Filter by CLOUDY_PIXEL_PERCENTAGE < 20 Pre-selects best images

8. Exporting Cloud-Free Images


Export.image.toDrive({ image: rgb.clip(region), description: 'Sentinel2_TrueColor', folder: 'GEE_exports', scale: 10, region: region, maxPixels: 1e13 });

Ideal for reports, map layouts, and temporal comparisons.


Conclusion

With proper cloud masking and visualization techniques, Sentinel-2 imagery in Google Earth Engine becomes a powerful tool for agriculture, forestry, urban monitoring, and environmental analysis. Using both QA60 and SCL-based methods, you can generate clean composites, calculate indices like NDVI, and export high-quality results.

By mastering these techniques, you ensure that your analysis is both visually accurate and scientifically reliable.

🔗 Related Articles:


COMMENTS

Name

CHIRPS,1,Climate,1,Cloud masking,1,DEM,1,EVI,3,Export,2,Fire forest,1,Forest,1,GEE,1,GEE Academy,3,GEE script,1,Image analysis,6,JRC,1,Landsat,1,LST,1,MODIS,4,NDVI,5,NOAA,1,remote sensing,2,Sentinel,2,Sentinel-2,1,Snow,1,SRTM,3,temperature,1,time series,1,vegetation index,3,VIIRS,1,
ltr
item
GEE Academy: Working with Sentinel-2 Imagery in GEE: Cloud Masking and Visualization
Working with Sentinel-2 Imagery in GEE: Cloud Masking and Visualization
Learn how to use cloud masking and visualize Sentinel-2 imagery in Google Earth Engine. Includes scripts for RGB, NDVI, and true-color composites.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd3AQvQqQw5261-TKKMu9-RBP81D9rySzc0N0U-MLy8eC-K5TDubJ8NDpfTt0nKagHPQaczFFYMEJeB6uIPcVcfG8DAlLsS4NNYAYNrsiNLXM9R-lpeXuXxDM8Sl76U1Tk67GErriD-WIlHHb7jEAK6-VK5RoIJfQ0hFtQo3OAfF1X_7EyutA6jtQCoPQ/w640-h426/Karavasta_Lagoon_Albania.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd3AQvQqQw5261-TKKMu9-RBP81D9rySzc0N0U-MLy8eC-K5TDubJ8NDpfTt0nKagHPQaczFFYMEJeB6uIPcVcfG8DAlLsS4NNYAYNrsiNLXM9R-lpeXuXxDM8Sl76U1Tk67GErriD-WIlHHb7jEAK6-VK5RoIJfQ0hFtQo3OAfF1X_7EyutA6jtQCoPQ/s72-w640-c-h426/Karavasta_Lagoon_Albania.jpg
GEE Academy
https://gee.geojamal.com/2025/04/working-with-sentinel-2-imagery-in-gee.html
https://gee.geojamal.com/
https://gee.geojamal.com/
https://gee.geojamal.com/2025/04/working-with-sentinel-2-imagery-in-gee.html
true
3421025227311197355
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content