Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
Morphological Operations
Stay organized with collections
Save and categorize content based on your preferences.
Earth Engine implements morphological operations as focal operations, specifically
focalMax()
, focalMin()
, focalMedian()
, and
focalMode()
instance methods in the Image
class. (These are
shortcuts for the more general reduceNeighborhood()
, which can input the
pixels in a kernel to any reducer with a numeric output. See
this page for more information on reducing
neighborhoods). The morphological operators are useful for performing operations such
as erosion, dilation, opening and closing. For example, to perform an
opening operation,
use focalMin()
followed by focalMax()
:
Code Editor (JavaScript)
// Load a Landsat 8 image, select the NIR band, threshold, display.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')
.select(4).gt(0.2);
Map.setCenter(-122.1899, 37.5010, 13);
Map.addLayer(image, {}, 'NIR threshold');
// Define a kernel.
var kernel = ee.Kernel.circle({radius: 1});
// Perform an erosion followed by a dilation, display.
var opened = image
.focalMin({kernel: kernel, iterations: 2})
.focalMax({kernel: kernel, iterations: 2});
Map.addLayer(opened, {}, 'opened');
Note that in the previous example, a kernel argument is provided to the morphological
operator. The pixels covered by non-zero elements of the kernel are used in the
computation. The iterations argument indicates how many times to apply the operator.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eEarth Engine uses focal operations like \u003ccode\u003efocalMax()\u003c/code\u003e, \u003ccode\u003efocalMin()\u003c/code\u003e, \u003ccode\u003efocalMedian()\u003c/code\u003e, and \u003ccode\u003efocalMode()\u003c/code\u003e to implement morphological operations for image processing.\u003c/p\u003e\n"],["\u003cp\u003eMorphological operations, such as erosion, dilation, opening, and closing, can be performed using these focal operations to modify image structures.\u003c/p\u003e\n"],["\u003cp\u003eUsers can define kernels to specify the shape and size of the neighborhood used in the operations and control the number of times the operation is applied with the iterations argument.\u003c/p\u003e\n"],["\u003cp\u003eAn opening operation, for example, can be achieved by applying \u003ccode\u003efocalMin()\u003c/code\u003e followed by \u003ccode\u003efocalMax()\u003c/code\u003e with a defined kernel.\u003c/p\u003e\n"]]],["Earth Engine's `Image` class provides `focalMax()`, `focalMin()`, `focalMedian()`, and `focalMode()` for morphological operations like erosion, dilation, opening, and closing. These operations use a kernel to define the neighborhood of pixels. For example, the opening operation is achieved by applying `focalMin()` then `focalMax()`. A kernel argument defines the area for computation, and the iterations argument specifies the number of operator applications. The provided code demonstrates the opening operation on a Landsat 8 image using a circular kernel.\n"],null,["# Morphological Operations\n\nEarth Engine implements morphological operations as focal operations, specifically\n`focalMax()`, `focalMin()`, `focalMedian()`, and\n`focalMode()` instance methods in the `Image` class. (These are\nshortcuts for the more general `reduceNeighborhood()`, which can input the\npixels in a kernel to any reducer with a numeric output. See\n[this page](/earth-engine/guides/reducers_reduce_neighborhood) for more information on reducing\nneighborhoods). The morphological operators are useful for performing operations such\nas erosion, dilation, opening and closing. For example, to perform an\n[opening operation](http://en.wikipedia.org/wiki/Opening_(morphology)),\nuse `focalMin()` followed by `focalMax()`:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 image, select the NIR band, threshold, display.\nvar image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')\n .select(4).gt(0.2);\nMap.setCenter(-122.1899, 37.5010, 13);\nMap.addLayer(image, {}, 'NIR threshold');\n\n// Define a kernel.\nvar kernel = ee.Kernel.circle({radius: 1});\n\n// Perform an erosion followed by a dilation, display.\nvar opened = image\n .focalMin({kernel: kernel, iterations: 2})\n .focalMax({kernel: kernel, iterations: 2});\nMap.addLayer(opened, {}, 'opened');\n```\n\nNote that in the previous example, a kernel argument is provided to the morphological\noperator. The pixels covered by non-zero elements of the kernel are used in the\ncomputation. The iterations argument indicates how many times to apply the operator."]]