我们在获取影像的百分比值使用的函数是ee.Reducer.percentile,但是会存在很多问题有时候会发现我们获取不同百分比值的时候数值会不一样,可能导致结果不同。
问题:
对于单波段图像,第5、25、50、75和95百分位数的值是相同的。尽管图像中存在离群点,但这很难理解,因为离群点像素的数量比正常像素的数量少得多。如何自动去除离群点?
函数:
ee.Reducer.percentile(percentiles, outputNames, maxBuckets, minBucketWidth, maxRaw)
Create a reducer that will compute the specified percentiles, e.g. given [0, 50, 100] will produce outputs named 'p0', 'p50', and 'p100' with the min, median, and max respectively. For small numbers of inputs (up to maxRaw) the percentiles will be computed directly; for larger numbers of inputs the percentiles will be derived from a histogram.
Arguments:
percentiles (List):
A list of numbers between 0 and 100.
outputNames (List, default: null):
A list of names for the outputs, or null to get default names.
maxBuckets (Integer, default: null):
The maximum number of buckets to use when building a histogram; will be rounded up to a power of 2.
minBucketWidth (Float, default: null):
The minimum histogram bucket width, or null to allow any power of 2.
maxRaw (Integer, default: null):
The number of values to accumulate before building the initial histogram.
Returns: Reducer
代码:
var geometry =
/* color: #d63000 */
/* shown: false */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[116.01553161700186, 37.83468958950668],
[116.01553161700186, 36.86089892709646],
[117.21304138262686, 36.86089892709646],
[117.21304138262686, 37.83468958950668]]], null, false);
var image=ee.ImageCollection("JAXA/ALOS/AW3D30/V3_2").select("DSM").filterBounds(geometry).mosaic().clip(geometry)
//original
var list1 = image.reduceRegion(ee.Reducer.percentile([5,25,50,75,95]),geometry,10,null,null,false,1e12)
print(list1) // the value of each percentile is same
var chart = ui.Chart.image.histogram({
image:image,
region:geometry,
scale:10,
minBucketWidth:0.1,
maxPixels:1e12
});
print('image historgram with outliers:',chart)
// munmual change outliers
var image2 = image.where(image.gt(10),10)
var list2 = image2.reduceRegion(ee.Reducer.percentile([5,25,50,75,95]),geometry,10,null,null,false,1e12)
print(list2)
var chart2 = ui.Chart.image.histogram({
image:image2,
region:geometry,
scale:10,
minBucketWidth:0.1,
maxPixels:1e12
});
print('image historgram without outliers:',chart2)
//修改后的代码///
// Finding the 5th and 95th percentile
var image_95 = image.reduceRegion({
'reducer': ee.Reducer.percentile({
'percentiles': [1, 5,25,50,75,95],
'maxRaw': 1000000,
'maxBuckets': 1000000,
'minBucketWidth': 0.00000000001
}),
'geometry': geometry,
'scale': 10,
'maxPixels': 1e13
});
print(image_95);