Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to normalize the values attained from a band ratio to 0-255. I'm using QGIS. How do I do this? Any ideas?

share|improve this question
1  
Because it's a ratio, watch out! E.g., if it's a ratio of two 0-255 images with equalized histograms, then half the ratios will be between 0 and 1 while the other half will be between 1 and 255 (and some will be undefined): that's a huge discrepancy in ranges! Depending on your purpose, the logarithm of the ratio might be a better quantity to compute; better yet, compute log((1+band1)/(1+band2)) to avoid undefined quantities. At the very least this will produce a more readable map. –  whuber Jun 29 '12 at 16:00
add comment

2 Answers

up vote 4 down vote accepted

You can use gdal_translate utility. Use the option -scale [src_min src_max [dst_min dst_max]] with src_min and src_max as current min/max values from your data and 0,255 as dst_min,dst_max.

If you have installed QGIS with OSGeo4W package, you may have the terminal program called 'MSYS'. Open that and just use the gdal_translate command. If not, from within QGIS choose Raster -> Conversion - > Translate. Choose your files and options. At the bottom of the window the full gdal_translate command will be displayed. Click edit and add the -scale option.

share|improve this answer
add comment

The following will stretch your data to 8-bit (0-255).

smin=0; smax=255

( x - min(x) ) * smax / ( max(x) - min(x) ) + smin

It should be fairly easy to translate this to the raster algebra syntax in your software of choice. You will just need to know what the min and max values are in your raster. If the raster is the result of a band ratio then it is safe to assume -1 to 1 and the syntax should look something like this.

NewRaster = ( OldRaster - -1 ) * 255 / ( 1 - -1 ) + 0
share|improve this answer
    
+1: General answers (syntax independent) have broad application. Welcome to our site, Jeffrey! –  whuber Jun 29 '12 at 18:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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