如何仅显示 Google Earth Engine 无监督分类中的一个集群
How to show only one of the clusters in Goole Earth Engine unsupervised classification
假设我们有以下无监督分类代码。我的目标是确定该地区的水体。我如何屏蔽其他 类(簇)并在我的结果中只映射其中一个簇(水体):
// Load a pre-computed Landsat composite for input
var input = ee.Image('LANDSAT/LE7_TOA_1YEAR/2001');
// Define a region in which to generate a sample of the input.
var region = ee.Geometry.Rectangle(29.7, 30, 32.5, 31.7);
// Display the sample region.
Map.setCenter(31.5, 31.0, 8);
Map.addLayer(ee.Image().paint(region, 0, 2), {}, 'region');
// Make the training dataset.
var training = input.sample({
region: region,
scale: 30,
numPixels: 5000
});
// Instantiate the clusterer and train it.
var clusterer = ee.Clusterer.wekaKMeans(5).train(training);
// Cluster the input using the trained clusterer.
var result = input.cluster(clusterer);
// Display the clusters with random colors.
Map.addLayer(result.randomVisualizer(), {}, 'clusters');
我只需要簇 (0),这样我就可以使用下面的代码屏蔽 类 的其余部分:
// showing only one cluster.
var subset = result.select("cluster").eq(0).selfMask();
假设我们有以下无监督分类代码。我的目标是确定该地区的水体。我如何屏蔽其他 类(簇)并在我的结果中只映射其中一个簇(水体):
// Load a pre-computed Landsat composite for input
var input = ee.Image('LANDSAT/LE7_TOA_1YEAR/2001');
// Define a region in which to generate a sample of the input.
var region = ee.Geometry.Rectangle(29.7, 30, 32.5, 31.7);
// Display the sample region.
Map.setCenter(31.5, 31.0, 8);
Map.addLayer(ee.Image().paint(region, 0, 2), {}, 'region');
// Make the training dataset.
var training = input.sample({
region: region,
scale: 30,
numPixels: 5000
});
// Instantiate the clusterer and train it.
var clusterer = ee.Clusterer.wekaKMeans(5).train(training);
// Cluster the input using the trained clusterer.
var result = input.cluster(clusterer);
// Display the clusters with random colors.
Map.addLayer(result.randomVisualizer(), {}, 'clusters');
我只需要簇 (0),这样我就可以使用下面的代码屏蔽 类 的其余部分:
// showing only one cluster.
var subset = result.select("cluster").eq(0).selfMask();