google earth engine

i need to do clustering within classes to increase size of training sample

any idea for gee code

var geometryProperty = 'geometry';
var classProperty = 'ID';

var emptyImage = ee.Image().byte();

var performClustering = function(cropID) {
var cropSamples = data.filter(ee.Filter.eq(classProperty, cropID));

var clusterer = ee.Clusterer.wekaKMeans(10);
var clusters = clusterer.train(cropSamples);

// Assign cluster IDs to the crop samples
var samplesWithCluster = cropSamples.map(function(sample) {
var cluster = clusters.predict(sample);
return sample.set('cluster', cluster);
});

// Return the samples with cluster IDs
return samplesWithCluster;
};

// Generate variety samples within each crop by clustering
var varietySamples = data
.aggregate_array(classProperty)
.distinct()
.map(function(cropID) {
return performClustering(cropID);
});

// Combine the variety samples with the original training samples
var trainingSamples = data
.merge(varietySamples.flatten());

// Convert the labeled image to an image collection
var labeledImage = emptyImage.paint(trainingSamples, classProperty);
var imageCollection = ee.ImageCollection.fromImages([labeledImage]);

0 1 176
1 REPLY 1

This is a forum for Apigee. I think you are asking about something that is unrelated to Apigee. You will probably want to try a different forum. Good luck!