How do you calculate standard deviation for each raster if you have set of rasters (100)? I was searching in raster calculator, but I didnt find it. Also google redirect me to using R or python. But I have just started learning.

So is there som easy way? Or I should really start learning python / R.

I have seen one post here. About Grass, but they was calculating stdev. across multiple rasters.

  • Do you want to calculate the standard deviation across the entire raster, or in parts of it? – Mikkel Lydholm Rasmussen Oct 22 '15 at 14:56
  • @MikkelLydholmRasmussen i have split one raster to many small... So for parts....right now Im looking at RasterStats plugin, but it seems like it is not working on new qgia – ABCD Oct 22 '15 at 14:59
  • You could look at Zonal Statistics. It does focus on using polygons, as zones, but you should be able to relatively easily create those polygons from your small rasters. See qgis.org/en/site/forusers/visualchangelog210/… – Mikkel Lydholm Rasmussen Oct 22 '15 at 15:08

One method which I used quite a while ago was to print the standard deviations in the Python Console in QGIS. I would first load all the raster layers (easier if they're kept in the same directory):

import os, glob

raster_path = "C:\Users\You\Desktop\Raster_folder\\"   # Path to directory containing rasters

for raster in glob.glob(raster_path + "*.tif"):
    layer = QgsRasterLayer(raster, os.path.basename(raster))


Then use the following to iterate through the layers and print the standard deviation:

layers = QgsMapLayerRegistry.instance().mapLayers().values()
for layer in layers:
    ext = layer.extent()
    print layer.name() + ":", "stdDev = ", stats.stdDev

Hope this helps!


You don't need to write code if you have GDAL installed (if you have QGIS installed that should be the case, but you can install GDAL seperately if you want/need to)

This assumes you want a separate stddev for each image. If you want the stddev across ALL the images, you'll need to do a Raster Merge to combine them into a single raster.

The gdalinfo tool with its-stats option will spit out several summary stats for each band in a raster:-

... snip ...
Band 1 Block=1000x1 Type=Float32, ColorInterp=Undefined
  Min=11.550 Max=26.510 
  Minimum=11.550, Maximum=26.510, Mean=14.233, StdDev=0.837
  NoData Value=-9999

If you're using Linux, a short script can be set up to extract the STDDEV for mutiple files. In this case I'm running against hundreds of small ascii grid tiles of Open Lidar Data, and getting a separate stddev for each. You can simply change this to *.tiff; GDAL supports lots of raster formats.

for i in $( ls *.asc); do
  gdalinfo -stats $i | grep STDDEV

You should be able to do something similar on Windows if you're using that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.