公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
形态学运算
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Earth Engine 将形态学运算实现为焦点运算,具体而言,就是 Image
类中的 focalMax()
、focalMin()
、focalMedian()
和 focalMode()
实例方法。(这些是更通用的 reduceNeighborhood()
的快捷方式,可将内核中的像素输入到具有数值输出的任何 reducer。如需详细了解如何减少邻区,请参阅此页面。形态学运算符非常适合执行侵蚀、膨胀、开运算和闭运算等操作。例如,如需执行打开操作,请使用 focalMin()
后跟 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');
请注意,在上例中,系统会向形态学运算符提供核参数。核的非零元素所覆盖的像素会用于计算。iterations 参数表示要应用运算符的次数。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\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."]]