I want to apply the following condition statement to all the pixels of an indices image having only 1 band. The condition is as follows-
For that first I have calculated the mean value of my image. Next I have printed the bands existing and then used the expression by substituting the band values.
var mean = MNDWI.reduceRegion(ee.Reducer.mean(),clip_layer,28);
print('mean', mean)
var band_names = MNDWI.bandNames();
print(band_names)
var index = MNDWI
var recode = ee.Image().expression(
'(mean > 0 and index >= mean) or ' +
'(mean <= 0 and index >= (mean**5 - 0.02)) ' +
'? 254 : 0', {
mean: mean,
index: index
})
Map.addLayer(recode)
Here (MNDWI) represents the index, and "B3" is the single band that index is having which can be observed in the print statement output.
But I am getting this error-
Layer error: Image.gt, argument 'image1': Invalid type.
Expected type: Image.
Actual type: Dictionary.
Actual value: {B3=-0.14653535282222163}
Best Answer
The error message is almost certainly accurate.
MBUI
probably doesn't have aB3
band. But your code isn't complete enough to say.As for the expression, to do power, you don't use
^
but**
. It also doesn't correctly implement your specified condition. You could perhaps implement it like this:https://code.earthengine.google.com/dd2052391c15a82c4d9d53cc9c1797fc