For treating landscape elements as objects, Earth Engine contains several methods. Specifically, when an image has distinct patches identified by unique pixel values, use image.connectedPixelCount() to compute the number of pixels in each patch and image.connectedComponents() to label each patch with a unique identifier. The unique identifiers can then be used to enumerate the patches and analyze the distribution of size or some other quality of interest. The following computes the size and unique identifiers of hot patches in a surface temperature image:
为了将景观元素视为对象,Earth Engine包含多种方法。具体而言,当图像具有由唯一像素值标识的不同patch时,可以使用 image.connectedPixelCount()计算每个补丁中的像素数并使用 image.connectedComponents()方法计算每个patch的唯一标识符标记。然后,可以使用唯一标识符来枚举patch并分析大小的分布或一些其他感兴趣的方面。以下计算表面温度图像中hot patch的大小和唯一标识符:
// Load a Landsat 8 image and display the thermal band.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');
Map.setCenter(-122.1899, 37.5010, 13); // SF Bay
Map.addLayer(image, {bands: ['B10'], min: 270, max: 310}, 'LST');
// Threshold the thermal band to find "hot" objects.
var hotspots = image.select('B10').gt(303);
// Mask "cold" pixels.
hotspots = hotspots.updateMask(hotspots);
Map.addLayer(hotspots, {palette: 'FF0000'}, 'hotspots');
// Compute the number of pixels in each patch.
var patchsize = hotspots.connectedPixelCount(256, false);
Map.addLayer(patchsize, {}, 'patch size');
// Uniquely label the patches and visualize.
var patchid = hotspots.connectedComponents(ee.Kernel.plus(1), 256);
Map.addLayer(patchid.randomVisualizer(), {}, 'patches');
In the previous example, note that the maximum patch size is set to 256 pixels by the arguments to the connectedPixelCount() and connectedComponents() methods. The connectivity is also specified by the arguments, in the former method by a boolean and in the latter method by an ee.Kernel. In this example, only four neighbors are considered for each pixel.
在前面的示例中,请注意,connectedPixelCount()和和connectedComponents() 方法的参数将最大patch的大小设置为256像素。connectivity参数也被指定,在前一个方法中由布尔值指定,后一个方法由一个ee.Kernel指定。在该示例中,对于每个像素仅考虑四个相邻像素。