TransWikia.com

Google Earth Engine: Apply scaling function to band values of image

Geographic Information Systems Asked by Joris on December 28, 2020

Situation

I would like to use a support vector regression model to predict a continuous outcome (percentage bareground cover). As predictors, I am using a number of different Landsat composite bands.
Here is a selection of band values:

enter image description here

As you can see, the band values are on very different scales, which leads me to believe that they should be scaled for the regression model.

Here is an example of a Landsat image with band values of very different scale (e.g. Band 9 vs. Band 10):
https://code.earthengine.google.com/?scriptPath=users%2Fjwiethase%2FTZ_restoration%3AUntitledFile2

Tried so far

It seems that a sensible scaling formula would be something like this:

scaled value = (x - mean(x)) / sd(x)

I know that I can apply some calculations to all bands of the image by using functions like .divide(), and calculate the average of a band using the reducer ee.Reducer.mean().

Question

How do I put it all together, to apply the scaling function to every value in every band of an image?

The desired outcome is an image with the same number of bands and band values, but each value scaled based on the function using the respective band average and standard deviation.

One Answer

To answer my own question:

We can apply a scaling function to the bands following the answer to this post:

var get_mean = my_image.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: my_image.geometry(),
  scale: 30,
  maxPixels: 10e9
}); 

var get_sd = my_image.reduceRegion({
  reducer: ee.Reducer.stdDev(),
  geometry: my_image.geometry(),
  scale: 30,
  maxPixels: 10e9
}); 

var imaged_normalized = ee.ImageCollection.fromImages(
  my_image.bandNames().map(function(name){
    name = ee.String(name);
    var band = my_image.select(name);
    return band.expression(
      '(x - mean_x) / sd_x', {
        'x': band,
        'mean_x': ee.Number(get_mean.get(name)),
        'sd_x': ee.Number(get_sd.get(name))})
  })).toBands().rename(my_image.bandNames());

Answered by Joris on December 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP