I ran a supervised classification in Google Earth Engine (GEE) using the following script.
// add an image, bounds, filter data and sort by cloud cover
var limitiNapoli = 'PathToMyasset'
var image = ee.Image(ee.ImageCollection(sentinel)
.filterBounds(roi)
.filterDate('2019-07-01', '2019-07-28')
.sort('CLOUD_COVERAGE_ASSESSMENT')
.first());
//Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'image');
var imageNapoli = image.clip(limitiNapoli)
// Map.addLayer(imageNapoli, "", "ImageNapoli")
print (image)
// training data and merge. Printing training data
var newfc = urban.merge(water).merge(forest).merge(crops);
// 'B2', 'B3', 'B4'
var bands = [ 'B5', 'B6', 'B7', 'B8', 'B8A', 'B11', 'B12' ];
var training = image.select(bands).sampleRegions({
collection: newfc,
properties: ['landcover'],
scale : 10
});
print(training);
var trueColor = {
bands: [ "B4", "B3", "B2"],
min: 0,
max: 3000 };
// train the classifier
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: 'landcover',
inputProperties: bands
});
// run the classification
var classified = image.select(bands).classify(classifier);
// display classification
Map.centerObject(newfc, 12);
Map.addLayer(imageNapoli, trueColor, 'Sentinel image Napoli');
Map.addLayer(classified.clip(limitiNapoli),
{ min: 0, max: 3, palette: ['CF521F', '39C3EE', '2F9516', '53FD29']},
'classification');
// Map.addLayer(newfc);
Map.addLayer(limitiNapoli, "", "Limiti Comune Napoli")
Export.image.toDrive({
image: classified, // <----- put the image you want to download
description: "Land Cover Classification",
scale: 10, // <------ set the pixel size in meters
region: exportation
});
As output i have a raster in which the pixels are classified into 4 different classes: water, urban, forest and crops.
I would like to validate the forest pixels by running an accuracy assessment using some ground truth data i have from the field (polygons). How could i do it?