0

Suppose we have the following codes for unsupervised classification. My goal is to identify the water bodies across the area. How can I mask out other classes (clusters) and only map one of the clusters (water bodies)in my results:

// 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');
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Hossein Sa
  • 11
  • 3

1 Answers1

1

I only need the cluster (0) so I could mask the rest of the classes using the codes below:

// showing only one cluster.
var subset = result.select("cluster").eq(0).selfMask();
Hossein Sa
  • 11
  • 3