Strange NDVI Behavior - Dominant Red Color in Some Images:

I am reaching out to seek some guidance regarding a peculiar issue I’ve encountered while working with NDVI images, specifically related to the dominance of the red color without variation in certain images.

I have been diligently processing NDVI images for my project, and overall, the results have been satisfactory. However, I’ve noticed that in some instances, the NDVI images exhibit an unexpected behavior – the presence of only the red color without any discernible variation.

Here is my EvalScript:

private String getEvalScript() {
        return  "//VERSION=3\n" +
            "function setup() {\n" +
            "   return {\n" +
            "      input: [\"B04\", \"B08\", \"dataMask\"],\n" +
            "      output: { bands: 4 }\n" +
            "   };\n" +
            "}\n" +
            "\n" +
            "const ramp = [\n" +
            "    [\"-1\", \"0x000000\"],         // Black\n" +
            "    [\"-0.2\", \"0xa50026\"],       // Dark Red\n" +
            "    [\"0\", \"0xd73027\"],          // Red\n" +
            "    [\"0.1\", \"0xf46d43\"],        // Light Orange\n" +
            "    [\"0.2\", \"0xfdae61\"],        // Dark Orange\n" +
            "    [\"0.3\", \"0xfee08b\"],        // Light Yellow\n" +
            "    [\"0.4\", \"0xffffbf\"],        // Pale Yellow\n" +
            "    [\"0.5\", \"0xd9ef8b\"],        // Light Yellow-Green\n" +
            "    [\"0.6\", \"0xa6d96a\"],        // Medium Green\n" +
            "    [\"0.7\", \"0x66bd63\"],        // Dark Green\n" +
            "    [\"0.8\", \"0x1a9850\"],        // Very Dark Green\n" +
            "    [\"1\", \"0x006837\"]           // Forest Green\n" +
            "];\n" +
            "const visualizer = new ColorRampVisualizer(ramp);\n" +
            "function evaluatePixel(samples) {\n" +
            "   let ndvi = index(samples.B08, samples.B04);\n" +
            "   let imgVals = visualizer.process(ndvi);\n" +
            "   return imgVals.concat(samples.dataMask);\n" +
            "}\n";
    }

Not sure if I am getting those dominant red color because cloud coverage, but is there a way to check if the image is covered and also get the percentage of clouds?

Hi Agrare,

I’m fairly certain that this is caused by cloud cover. You can check this by visualising the SCL layer as this is Sentinel-2 data I think (based on the bands). You can use this evalscript to check this :slight_smile:

//VERSION=3

 function RGBToColor (r, g, b,dataMask){
	return [r/255, g/255, b/255,dataMask];
}

function setup() {
   return {
    input: ["SCL","dataMask"],
    output: { bands: 4 }
  };
}

function evaluatePixel(samples) {
    const SCL=samples.SCL;
    switch (SCL) {
    // No Data (Missing data) (black)    
    case 0: return RGBToColor (0, 0, 0,samples.dataMask);
        
    // Saturated or defective pixel (red)   
    case 1: return RGBToColor (255, 0, 0,samples.dataMask);

    // Dark features / Shadows (very dark grey)
    case 2: return RGBToColor (47,  47,  47,samples.dataMask);
        
    // Cloud shadows (dark brown)
    case 3: return RGBToColor (100, 50, 0,samples.dataMask);
        
    // Vegetation (green)
    case 4: return RGBToColor (0, 160, 0,samples.dataMask);
        
    // Not-vegetated (dark yellow)
    case 5: return RGBToColor (255, 230, 90,samples.dataMask);
        
    // Water (dark and bright) (blue)
    case 6: return RGBToColor (0, 0, 255,samples.dataMask);
    
    // Unclassified (dark grey)
    case 7: return RGBToColor (128, 128, 128,samples.dataMask);
    
    // Cloud medium probability (grey)
    case 8: return RGBToColor (192, 192, 192,samples.dataMask);
        
    // Cloud high probability (white)
    case 9: return RGBToColor (255, 255, 255,samples.dataMask);
    
    // Thin cirrus (very bright blue)
    case 10: return RGBToColor (100, 200, 255,samples.dataMask);
        
    // Snow or ice (very bright pink)
    case 11: return RGBToColor (255, 150, 255,samples.dataMask);

    default : return RGBToColor (0, 0, 0,samples.dataMask);  
    }
}
1 Like

Hi William,

Thank you, with this SCL layer I was able to check the cloud coverage, now I think the images are being generated as expected.

Really appreciate your reply :slight_smile: