Altering Gain and Gamma in Evalscript

Hello,

I am trying to save a georeferenced satellite image with altered gain and gamma parameters. However, the visualized effects will not allow me to do so. I am wondering, if it is possible, how I would be able to alter the gain and gamma parameters in the evalscript itself? In doing so, would this workaround allow me to save a georeferenced satellite image?

Thank you.

Hi!

Thanks for the post and welcome to the Sentinel Hub community! :raised_hands:

I’m making the assumption that you are using EO Browser currently, where you can adjust the gain and gamma parameters externally from the evalscript. It is possible to do this within the evalscript though using one of the Utility functions named HighlightCompressVisualizer. You will also probably want to save this as a GeoTIFF too which is possible using our APIs. This is probably also a great time to familiarise yourself with the Request Builder application which is a little easier to use when adjusting your evalscripts :+1:

Let us know how you get on :smile:

1 Like

A simplified method that I use and that you may find useful to replicate gain and gamma in an Evalscript is the following (please note that this is empirical and has no sound scientific basis but may be fun to play around with):

Gain

Gain may be seen as a simple amplification of the signal. For that I use multiplication. Example:

//VERSION=3
function setup() {
  return {
    input: ["B05"],
    output: { bands: 1}
  };
}

// Set gain
const gain = 4

function evaluatePixel(sample) {
  var band = sample.B05
  return [band * gain]
}

Gamma

Gamma correction is the process to encode linear values into a non-linear relationship. You can use the HighlightCompressVisualizer function as @william.ray mentioned, or you can keep it simple and use exponentiation in your Evalscript:

//VERSION=3
function setup() {
  return {
    input: ["B05"],
    output: { bands: 1}
  };
}

// Set gamma
const gamma = 0.6

function evaluatePixel(sample) {
  var band = sample.B05
  return [Math.pow(band, gamma)]
}

And given that gamma correction is exponential, therefore scale sensitive, and is done on the scale of 0-1, we don’t need to normalise (reflectance is generally between 0 and 1).