I have 3 different independent layers which I want to merge into one layer:
For creating those layers, I have calculted NDVI, calculted the mean and then I have created one layer that is lower than the mean value, one layer that is higher and one ehich is the mean. I want now to take those 3 layers and merge them into one.
I have read all the section of the mosaicking but as I understand, I can't just merge those 3 layers.
Is there any way to merge those layers into one ? I thought to create visualization based ont their values but I saw I can't use this calssify.
This is how I created the 3 different layers:
var MyImage=ee.Image(withNDVI.first());
Map.addLayer(MyImage,colorizedVis,'ndvi');
//var std2 = ee.Number(STDDictionary.get("NDVI")).divide(2);
// var mean1 = ee.Number(meanDictionary.get("NDVI"));
///////the good function I want to work with:///////
for (var i in MyImage){
var reducers = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
var meanDictionary = MyImage.reduceRegion({
reducer: reducers,
bestEffort: true,
});
}
print(meanDictionary);
//calculation
var std2 = ee.Number(meanDictionary.get('NDVI_stdDev')).divide(2);
var mean1 = ee.Number(meanDictionary.get("NDVI_mean"));
// the classes borders
var negBorder=mean1.subtract(std2);
var posBorder=mean1.add(std2);
//create the layers
var imageNDVI=MyImage.select('NDVI');
var gtPOS=MyImage.gt(posBorder).selfMask().rename('PositiveBorder');
var ltNEG=MyImage.lt(negBorder).selfMask().rename('NegativeBorder');
var betMEAN=MyImage.gt(negBorder).and(imageNDVI.lt(posBorder)).selfMask().rename('MeanBorder');
var PositiveCOL = {
palette: [
'006622'
],
};
var NegativeCOL = {
palette: [
'ff0000'
],
};
var MeanCOL = {
palette: [
'00ff00'
],
};
Map.addLayer(gtPOS,PositiveCOL,'High');
Map.addLayer(ltNEG,NegativeCOL,'Low');
Map.addLayer(betMEAN,MeanCOL,'Mean');
I have try mosaic like this but got null image:
var mosaic = ee.ImageCollection.fromImages([gtPOS, ltNEG,betMEAN]).mosaic();
var PalMos={
palette:[
'006622','ff0000','00ff00']
};
Map.addLayer(mosaic,PalMos,'Mosaic');
but got this error:
Mosaic: Tile error: Expected a homogeneous image collection, but an image with incompatible bands was encountered: First image type: 1 bands ([PositiveBorder]). Current image type: 1 bands ([NegativeBorder]). Image ID: 1 Some bands might require explicit casts.
My end goal: to merge those 3 different classifications into 1 layers, right now they are 3 independent layers.