Automatic stretching of the raster histogram in QGIS

01.03.2011 15:01 ·  GIS  ·  qgis, tips

QGIS allows you to save a default raster band combination, standard deviation and contrast enhancement algorithm for rasters.

But it seems that not many people use this feature. At least no one noticed that although the band combination and standard deviation can be saved, they are of no use because the saved values are not applied when the raster is loaded. There were also other problems (for example, the default band combination is 5-4-3, but the raster properties show 1-2-3) that no one reported.

All this has been around for a long time, somewhere since r13582 or even earlier. And only in r15256 were all these problems finally solved.

I’ll try to explain why you might need it and how to use it.

As you know, the number of bands in raster data can often be more than three, e.g. Landsat data has 8 channels. When working with such rasters, the standard combination of bands 1-2-3 (channel 1 - R, channel 2 - G, channel 3 - B) is not suitable, the image will be uninformative.

Landsat raster with 1-2-3 band combination
Landsat raster with 1-2-3 band combination

For this type of data, a 5-4-3 combination is usually used; it looks a little better, but the image is still quite dark.

Landsat raster with 5-4-3 band combination
Landsat raster with 5-4-3 band combination

By applying the “Stretch to MinMax” contrast enhancement algorithm, we get an image we can work with.

Landsat raster with 5-4-3 band combination and contrast enhancement
Landsat raster with 5-4-3 band combination and contrast enhancement

To further emphasise the different regions, we can also set the standard deviation to 2.

Landsat raster with 5-4-3 band combination, contrast enhancement and std. deviation
Landsat raster with 5-4-3 band combination, contrast enhancement and std. deviation

If you save all these settings as default, then all rasters of this type will be loaded with the correct display settings without any further user action. At the same time, rasters with 1 or 3 bands will be loaded as usual, without stretching and with a 1-2-3 band combination.

Read more about common Landsat band combinations here and here.

⮜ Prev
Next ⮞