Rescale your raster data layer

Sometimes you want to rescale a raster layer, e.g., to reduce the number of categories, or to create a common scale for different raster layers. Very basic of course, so you can expect to find an appropriate function in any self-respecting GIS software. Just be aware that different terms are being used for the same thing, e.g., scale in gdal, rescale in GRASS and normalize in SAGA GIS. Below a few ways to do this using my favourite GIS programs: GRASS GIS, QGIS, SAGA GIS or gdal.

GRASS GIS

In GRASS GIS you can use the r.rescale function, which rescales the range of category values appearing in a raster map layer and, very conveniently, creates category labels that reflect the original category values that produced each category.

 r.rescale input=elevation from=10,1500 output=elevation_255 to=0,255

But note, it only supports integer data. If you have floating data, you can use the r.recode function:

r.recode input=elevation output=elevation_25 rules=- << EOF
    10.1:1500.5:0.5:255
EOF

 

GDAL

Use the scale parameter in the gdal_translate function to rescale the input pixels values from the original range to the desired range.

gdal_translate -scale 10 1500 0 255 elevation.tif elevation_255.tif

 

QGIS

In QGIS you can use the SAGA GIS function grid_normalisation (available through the Processing toolbox in QGIS under SAGA) or the above-mentioned gdal_translate function, which is available under the raster menu or in the Processing toolbox under GDAL/OGR algorithms.

Screenshot1

Screenshot2

 

SAGA GIS

SAGA GIS function grid_normalisation

Screenshot3

The nice thing about having different options is that you are very likely to find a way that fits best in your work flow, whether it involved the command line or GUI.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s