This blog covers unsupervised classification in the Google earth engine.
Source: Google Earth Engine
The process of unsupervised classification in GEE is carried out using the ee.Clusterer package. The package has been adopted from Weka
- Loading of the image
The image used in classification is from the landsat program. A landsat 7 image is used for the year 2001.
// Load a pre-computed Landsat composite for input.var input = ee.Image(‘LANDSAT/LE7_TOA_1YEAR/2001’); |
- Creating and display of the region of interest.
The region of interest is created using the geometry tool, centered to the map and displayed.
Figure 1: Geometry tool
Figure 2: Importing the image
// Display the sample region.Map.setCenter(34.75, 0.282);
Map.addLayer(ee.Image().paint(region, 0, 2), {}, ‘region’); |
- Features with numeric properties in which to find clusters are assembled, while setting the necessary parameters including scale.
// Make the training dataset.var training = input.sample({
region: region, scale: 30, numPixels: 5000 }); |
- Training of the classifier
// Instantiate the clusterer and train it.var clusterer = ee.Clusterer.wekaKMeans(15).train(training); |
// Cluster the input using the trained clusterer.var result = input.cluster(clusterer); |
- Display of the results
The result is displayed using different colors, adopted from Visualization in the Google Earth Engine.
// Display the clusters Map.addLayer(result.randomVisualizer(), {}, ‘clusters’); |
Figure 3: Classification result
Full code:
// Load a pre-computed Landsat composite for input.var input = ee.Image(‘LANDSAT/LE7_TOA_1YEAR/2001’);
// Display the sample region. Map.setCenter(34.75, 0.282); 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(15).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’); |
Unsupervised classification in GEE