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:


Open All Collapse All Refresh Feeds
RSS Feeds & Updates
Geospatial Tools

GIS & Remote Sensing

Workflows and tutorials on spatial data and imagery analysis.

gis.geojamal.com

Remote Sensing Indices

Explore NDVI, SAVI, NDWI and many spectral indicators.

rs.geojamal.com

GeoAI & ML

Machine learning tools and spatial intelligence applications.

geoai.geojamal.com
Mapping & Visualization

Map Resources

Shapefiles, basemaps and vector tiles for GIS projects.

maps.geojamal.com

Earth Tools & Maps

Explore satellite viewers, terrain tools and visual apps.

earth.geojamal.com

Coordinate Tools

View, transform and clean coordinates on a live map.

coordinates.geojamal.com
AI & Smart Processing

GeoAI & ML

AI tools for automated analysis of Earth data.

geoai.geojamal.com

GEE Scripts & Apps

Google Earth Engine apps and tutorials.

gee.geojamal.com
Coordinate & File Converters

Geo Format Converter

Convert CSV, KML, GPX, GeoJSON, Excel, and more.

convert.geojamal.com

Coordinate Tools

Live projection and geocoding tools.

coordinates.geojamal.com
Learning Platforms

TV: English Tutorials

Video content for GEE, GIS, remote sensing in English.

tv.geojamal.com

TV: Arabic Tutorials

Arabic video lessons on mapping and geospatial analysis.

ar.tv.geojamal.com

How-To Guides

Written tutorials and step-by-step guides.

howto.geojamal.com

GeoJamal بالعربية

الموقع الرسمي للمحتوى العربي في نظم المعلومات الجغرافية، الاستشعار عن بعد، والخرائط الذكية.

ar.geojamal.com
Downloads & Resources

Downloads Center

Free GIS tools, satellite data, software and add-ons.

downloads.geojamal.com

SASPlanet Center

Offline satellite downloading and map exploration tools.

sasplanet.geojamal.com
GPS & Field Tools

GPS Utilities

Geotagged photos, live location, export to KML or GPX.

gps.geojamal.com

Coordinate Tools

Field-ready conversion and projection mapping support.

coordinates.geojamal.com
Multilingual Access

GeoJamal بالعربية

الموقع الرسمي للمحتوى العربي في نظم المعلومات الجغرافية، الاستشعار عن بعد، الذكاء الاصطناعي الجغرافي، وتحليل الخرائط.

ar.geojamal.com
Name

CHIRPS,1,Climate,1,Cloud masking,1,Crop Impact,1,DEM,1,Disaster Monitoring,1,EVI,3,Export,2,Fire forest,1,Flood Mapping,1,Forest,1,GEE,1,GEE Academy,3,GEE script,1,GEE Tutorial,1,GeoJamal,1,Google Earth Engine,1,Image analysis,6,JRC,1,Land Cover,1,Landsat,1,LST,1,MODIS,4,NDVI,5,NOAA,1,remote sensing,3,SAR Analysis,1,Sentinel,2,Sentinel-1,1,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