Skip to main content

NDVI relative in PNG (all NDVI value in whole ramp color)

  • April 26, 2024
  • 3 replies
  • 212 views

I want to create a function that put any NDVI data range in all ramp color, doesn’t matter the interval of the values. In other hands, I’m trying to create a NDVI relative when all ramp color represent the value range. I’m just tried the blend method in utility functions, but did not work as I expected. After, I used my own logic to build a way to do this as follow in the function:

function evaluatePixel(sample) {
  if ([3, 8, 9, 10].includes(sample.SCL) ){
    return [1, 0, 0]
  } else {
    let ndvi = (sample.B08 - sample.B04) / (sample.B08 + sample.B04);
    let min = Math.min.apply(ndvi);
    let max = Math.max.apply(ndvi); 
    let ndviRelative = (ndvi - min) / (max - min);
    return [...visualizer.process(ndviRelative), sample.dataMask] 

Ignoring the dataMask and SCL samples, note that I’m trying to use “Math.min/max.apply()” method to extract de min and max values from ndvi and use this in the formula that’s normalize any NDVI data between 0 and 1 to then, vizualize in a ramp color. However, the return it’s been an image with a single data (in attach). My partiners suspect that I have to use updateOutputMetadata instead evaluatePixel. So, what should I have to do?

response

3 replies

Thanks for the answer.It’s exactly what I want.

So, I need to make Statistical API for the max/min NDVI data and then, the process API, right?


Hi,

It seems to me that you’re trying to obtain the maximum and minimum NDVI value of your AOI and use the NDVI range to create a visualisation. If this is the case, this can’t be achieved in one request as Processing API is pixel-based and the maximum/minimum is unknown until the execution completes.

To create a visualisation based on the NDVI range of your AOI, you will have to make a Statistical API request first to get the maximum and minimum, then apply them to your Evalscript.


Yes, exactly. To parse a variable (the min/max in your case) to Evalscript, please you can have a look at cell 10 in this example.