-
Notifications
You must be signed in to change notification settings - Fork 8
/
imnormalize.js
27 lines (27 loc) · 949 Bytes
/
imnormalize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
This is a function to normalize image pixels in an imageCollection
Reference: https://gis.stackexchange.com/questions/313394/normalization-in-google-earth-engine
Shunan Feng: fsn.1995@gmail.com
*/
var normalization = function(image) {
var imMinMax = image.reduceRegion({
reducer: ee.Reducer.minMax(),
geometry: image.geometry(),
// scale: 1000,
maxPixels: 10e9,
bestEffort: true,
tileScale: 16
});
var imNorm = ee.ImageCollection.fromImages(
image.bandNames().map(function(name){
name = ee.String(name);
var band = image.select(name);
return band.unitScale(ee.Number(imMinMax.get(name.cat('_min'))), ee.Number(imMinMax.get(name.cat('_max'))));
})
);
return imNorm.toBands().rename(image.bandNames());
};
var imNormalize = function(imcollection){
return imcollection.map(normalization);
};
exports.imNormalize = imNormalize;