I'm trying to extract the brightest 100 pixels of a single band image. More specifically,
sort the pixel values of a single band image,
extract the top 100 pixel values,
put them into a list for further use.
Below is my solution based on a for-loop, but it's too slow and even failed when i > 100. Code link: https://code.earthengine.google.com/?scriptPath=users%2Fghongwei0309%2FGEE_ACO%3ABrightest_1000_Test
var dataset = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2018-04-05', '2018-06-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10));
var img = dataset.first().select('B3');
var ftpt = img.geometry(); //image footprint
var lst = ee.List([]);
for (var i=0; i<30; i++){
var maxVal = img.reduceRegion({
reducer: ee.Reducer.max(),
geometry: ftpt,
scale: 10,
crs: 'EPSG: 4326',
bestEffort: true
}).getNumber('B3');
img = img.updateMask(img.lt(maxVal));
maxVal = img.reduceRegion({
reducer: ee.Reducer.max(),
geometry: ftpt,
scale: 10,
crs: 'EPSG: 4326',
bestEffort: true
}).getNumber('B3')
lst = lst.add(maxVal);
};
print(lst.length());
How can I do this?