I am trying to improve image classification in GEE by using the STM of the mean. I first calculated the mean of the four bands.
Then I added the new column with mean to the image.
Then I used the new image with 5 bands (including the mean) to classify.
However, I keep getting errors in my classification. Here is my code:
Map.addLayer(image, imageVisParam);
Map.centerObject(image,11);
//select the bands
var bands = ['b1', 'b2', 'b3', 'b4'];
var stm = image.select(bands).reduce(ee.Reducer.mean()).rename('STM')
print(stm)
var classNames = Water.merge(BuiltupArea).merge(Cropland).merge(Vegetation).merge(Wetland).merge(clouds)
print(classNames);
var imageWithSTM = image.addBands(stm)
var classifier = ee.Classifier.smileRandomForest(50)
.train({
features: classNames,
classProperty: 'Class',
inputProperties: bands.concat(['STM'])
});
print(classifier, 'classifier')
var classified = imageWithSTM.classify(classifier)
print(classified, 'classified');
//Add the classification to the map view, specify colours for classes
Map.addLayer(classified,
{min: 0, max: 5, palette: ['0000FF', 'FF0000', '008000','FFFF00','98ff00','ffc82d']},
'classification')
I get this error when I run the codes: Image (Error) Property 'b1' of feature '0' is missing. classification: Layer error: Property 'b1' of feature '0' is missing.
How can I change my code to use all five bands or more in the classification without getting an error?