Min, median (median), mean (average), max in Reducer
The following example is for Image
var img = ee.Image("LANDSAT/LC08/C01/T1/LC08_127040_20190407");
Map.centerObject(img);
Map.addLayer(img,{},"img")
Map.addLayer(img.reduce(ee.Reducer.min()), {max: 5000}, 'Reducer.min()');
Map.addLayer(img.reduce(ee.Reducer.median()), {max: 10000}, 'Reducer.median() 中位数');//中位数
Map.addLayer(img.reduce(ee.Reducer.mean()), {max: 12000}, 'Reducer.mean() 平均值');//平均值
Map.addLayer(img.reduce(ee.Reducer.max()), {max: 30000}, 'Reducer.max()');
For the calculation of the maximum and minimum values of ImageCollection, you can directly use max and min for the image collection. For details, please refer to: https://blog.csdn.net/qq_40323256/article/details/109964468
ee.Reducer.allNonZero()
Check whether the inputs are all non-zero values, if they are all non-zero values, then return 1, otherwise 0
Reducer中的first、last、、firstNonNull、lastNonNull()
var l8 = ee.ImageCollection("LANDSAT/LO08/C01/T1_RT");
print("Reducer.first()",ee.List([12,21,3,14,5]).reduce(ee.Reducer.first()))//返回输入的第一个元素
print("Reducer.last()",ee.List([12,21,3,14,5]).reduce(ee.Reducer.last()))//返回输入的最后一个元素
print("Reducer.firstNonNull()",ee.List([null, 1,2,3,4,5]).reduce(ee.Reducer.firstNonNull()))//返回输入的第一个非null元素
print("Reducer.lastNonNull()",ee.List([1,2,3,4,5,null]).reduce(ee.Reducer.lastNonNull()))//返回输入的最后一个非null元素
AllNonZero, anyNonZero in Reducer
- allNonZero: Whether all values are not 0; as long as there is a value of 0, return 0; otherwise return 1
- anyNonZero: whether there is a value that is not 0; as long as there is a value that is not 0, return 1; otherwise, return 0
var l8 = ee.ImageCollection("LANDSAT/LO08/C01/T1_RT");
print("Reducer.allNonZero()1",ee.List([12,21,3,14,5]).reduce(ee.Reducer.allNonZero()))
print("Reducer.allNonZero()2",ee.List([12,21,3,0,14,5]).reduce(ee.Reducer.allNonZero()))
print("Reducer.allNonZero()3",ee.List([12,21,3,14,5,null]).reduce(ee.Reducer.allNonZero()))
print('-------------------------------------')
print("Reducer.anyNonZero()1",ee.List([12,21,3,14,5]).reduce(ee.Reducer.anyNonZero()))
print("Reducer.anyNonZero()2",ee.List([12,21,3,0,14,5]).reduce(ee.Reducer.anyNonZero()))
print("Reducer.anyNonZero()3",ee.List([0,0,0]).reduce(ee.Reducer.anyNonZero()))
print("Reducer.anyNonZero()4",ee.List([0,0,null]).reduce(ee.Reducer.anyNonZero()))