形态学运算

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 参数表示要应用运算符的次数。