Raster pixel values changing when raster is clipped

clipqgis-3rastersentinel-2

I have downloaded a couple of (Sentinel-2) raster files and would like to clip them down to be a smaller size. However, when I clip them the output file has a wider range of pixel values than the original file. For example, I clipped Band 2, which originally had values ranging from 0-1501. However after I applied the clip function reducing the total number of pixels the values ranged from 0-2132. I also tried mosaicking my (overlapping) files taking only the maximum value for each pixel to get rid of the 0 value areas and found the same thing to apply. I have tried this in QGIS 3.16.11 and also in 3.24.0 and no difference between the results.

Can anyone shed some light on what is happening here? I intend to use the pixel values to calculate NDVI so it is important that they are correct.

Best Answer

They're unlikely to have actually changed. These issues are usually caused by incorrect or poorly sampled approximate statistics. Recalculate the original and clipped statistics using exact instead of approximate method.

There's a few ways to do this

  1. Use the raster information tool and tick the first two min/max and stats options.
  2. There's also the raster layer statistics tool, but the help doesn't state whether it uses exact or approx stats.
  3. You can also specify to use exact stats in the raster layer properties - symbology - min/max values

Alternatively, use gdalinfo from the commandline:

gdalinfo -mm -stats your_raster.tif

This is exactly what option 1 above does.

Related Question