Smoothing Land Cover with Morphological Processing in GEE

SHARE:

Apply morphological filtering to MODIS land cover in GEE to remove noise and enhance classification consistency using erosion and dilation.

Land cover data, derived from satellite imagery, often contains noise and small, isolated regions that can hinder analysis. Morphological image processing techniques, such as erosion and dilation, can help to smooth and generalize land cover classifications, removing these artifacts. This article will guide you through a Google Earth Engine (GEE) script that demonstrates how to apply morphological processing to a MODIS land cover image to reduce noise and improve the spatial coherence of the classification.

Smoothing Land Cover in GEE


What This Script Does

This Google Earth Engine script processes a MODIS land cover image to smooth the classification and remove small, isolated regions. It employs a series of spatial filtering operations, including focal mode filtering, erosion, and dilation. The script also demonstrates how to force these operations to be performed at the native resolution of the input data using reprojection. This ensures that the processing is applied consistently and avoids artifacts that can arise from processing at varying pixel sizes.

Smothing Land Cover GEE Code Sample


// Morphological processing of land cover. 
// Force projection of 500 meters/pixel, which is the native MODIS resolution.
var SCALE = 500;
// Load a 2001 MODIS land cover image.
var image1 = ee.Image('MODIS/051/MCD12Q1/2001_01_01');
// Select the classification band of interest.
var image2 = image1.select(['Land_Cover_Type_1']);
// Reproject to WGS84 to force the image to be reprojected on load.
// This is just for display purposes, to visualize the input to
// the following operations.  The next reproject is sufficient
// to force the computation to occur at native scale.
var image3 = image2.reproject('EPSG:4326', null, SCALE);
// Smooth with a mode filter.
var image4 = image3.focal_mode();
// Use erosion and dilation to get rid of small islands.
var image5 = image4.focal_max(3).focal_min(5).focal_max(3);
// Reproject to force the operations to be performed at SCALE.
var image6 = image5.reproject('EPSG:4326', null, SCALE);
// Define display parameters with appropriate colors for the MODIS
// land cover classification image.
var PALETTE = [
    'aec3d4', // water
    '152106', '225129', '369b47', '30eb5b', '387242', // forest
    '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40', // shrub, grass, savannah
    '111149', // wetlands
    'cdb33b', // croplands
    'cc0013', // urban
    '33280d', // crop mosaic
    'd7cdcc', // snow and ice
    'f7e084', // barren
    '6f6f6f'  // tundra
].join(',');
var vis_params = {min: 0, max: 17, palette: PALETTE};
// Display each step of the computation.
Map.setCenter(-113.41842, 40.055489, 6);
Map.addLayer(image2, vis_params, 'IGBP classification');
Map.addLayer(image3, vis_params, 'Reprojected');
Map.addLayer(image4, vis_params, 'Mode');
Map.addLayer(image5, vis_params, 'Smooth');
Map.addLayer(image6, vis_params, 'Smooth');

Step-by-Step Explanation

Here's a breakdown of the code:

  1. Define the output scale:

    var SCALE = 500;

    This line defines a constant SCALE with a value of 500 meters. This represents the desired pixel size for the output images, which corresponds to the native resolution of the MODIS data.

  2. Load the MODIS land cover image:

    var image1 = ee.Image('MODIS/051/MCD12Q1/2001_01_01');

    This line loads a MODIS land cover image from the MCD12Q1 dataset for the year 2001. The ee.Image object represents the image data.

  3. Select the land cover classification band:

    var image2 = image1.select(['Land_Cover_Type_1']);

    The select() method is used to extract the 'Land_Cover_Type_1' band, which contains the primary land cover classification information.

  4. Reproject the image (for display):

    var image3 = image2.reproject('EPSG:4326', null, SCALE);

    This line reprojects the image to the WGS84 coordinate system ('EPSG:4326') and sets the pixel scale to 500 meters. This reprojection is primarily for display purposes, allowing you to visualize the original image in a standard geographic coordinate system. The null parameter indicates that no specific resampling method is specified, so the default method will be used.

  5. Apply a mode filter:

    var image4 = image3.focal_mode();

    The focal_mode() method applies a mode filter to the image. For each pixel, it determines the most frequent land cover value within a neighborhood (the default is a 3x3 neighborhood). This helps to smooth the image and reduce speckle or isolated pixels.

  6. Apply erosion and dilation:

    var image5 = image4.focal_max(3).focal_min(5).focal_max(3);

    This line applies a sequence of morphological operations:

    • focal_max(3): Dilation with a radius of 3 pixels. This operation expands the boundaries of land cover classes.
    • focal_min(5): Erosion with a radius of 5 pixels. This operation shrinks the boundaries of land cover classes.
    • focal_max(3): Dilation with a radius of 3 pixels. Another dilation to restore the size of the features after erosion.

    The erosion and dilation operations together remove small, isolated regions of land cover, further smoothing the classification. The order and radii of these operations are important for achieving the desired smoothing effect.

  7. Reproject the smoothed image:

    var image6 = image5.reproject('EPSG:4326', null, SCALE);

    This line reprojects the smoothed image (image5) to the WGS84 coordinate system with a pixel scale of 500 meters. This reprojection is crucial to ensure that all previous spatial operations are performed at the native resolution of the MODIS data. This prevents artifacts.

  8. Define visualization parameters:

    This section defines a color palette (PALETTE) that maps land cover class values to specific colors, and visualization parameters (vis_params) that specify the minimum and maximum pixel values and the palette to use when displaying the land cover images.

  9. Display the results:

    The Map.setCenter() line sets the center and zoom level of the map.

    The Map.addLayer() lines add the original and processed images to the map.

Datasets Used

MODIS Land Cover Type Yearly Global 500m (MCD12Q1), Collection 051: This dataset provides global land cover classifications derived from MODIS data.

Applications

This script demonstrates a valuable technique for improving the quality of land cover data, which has applications in various fields, including:

  • Land Use Change Analysis: Smoothing land cover maps can improve the accuracy of detecting changes over time.
  • Ecosystem Modeling: More accurate land cover data can lead to better estimates of ecosystem parameters.
  • Agricultural Monitoring: Removing noise from land cover classifications can help in identifying agricultural areas.
  • Urban Planning: Smoothing urban land cover classifications can improve the delineation of urban boundaries.
  • Climate Change Research: Accurate land cover data is essential for modeling.

Notes

  • The order and radii of the focal_max() and focal_min() operations are important.
  • The reproject() operation is crucial.
  • The PALETTE variable defines a color palette.

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: Smoothing Land Cover with Morphological Processing in GEE
Smoothing Land Cover with Morphological Processing in GEE
Apply morphological filtering to MODIS land cover in GEE to remove noise and enhance classification consistency using erosion and dilation.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnwFPhgy6KmsUUwfhuo3Z7UxTmGYLMQ2KXLvPBPHT9cyGM2zzKYP4VO_4sUppWabHfn3pFtGB5LuZZ5I93ihH3WAHQIxr7eh5f2UiXW9IJLcqSoLqER1Hp_wBgVf9Qtnbjouc03TjaEnx2cOjNSSWN5tHgCVhzWqXt9vzbkJMdT1mcCBVV6VU-c70WKVI/w640-h288/Earth%20Engine%20Code%20Editor.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnwFPhgy6KmsUUwfhuo3Z7UxTmGYLMQ2KXLvPBPHT9cyGM2zzKYP4VO_4sUppWabHfn3pFtGB5LuZZ5I93ihH3WAHQIxr7eh5f2UiXW9IJLcqSoLqER1Hp_wBgVf9Qtnbjouc03TjaEnx2cOjNSSWN5tHgCVhzWqXt9vzbkJMdT1mcCBVV6VU-c70WKVI/s72-w640-c-h288/Earth%20Engine%20Code%20Editor.png
GEE Academy
https://gee.geojamal.com/2025/04/smoothing-land-cover-with-morphological.html
https://gee.geojamal.com/
https://gee.geojamal.com/
https://gee.geojamal.com/2025/04/smoothing-land-cover-with-morphological.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