5

Is there a way to permanently stretch a histogram of a raster within QGIS or gdal? I would like to stretch a satellite image with a Standard Deviation 2.5 stretch. I would prefer to use QGIS or FWTools, but I am open to other open source tools.

Thanks...

1

A great and easy way to stretch the histogram of a raster seems to be gdal_contrast_stretch:

https://github.com/gina-alaska/dans-gdal-scripts/wiki/Gdal-contrast-stretch

Installation guide: https://github.com/gina-alaska/dans-gdal-scripts

Then you can use it as

gdal_contrast_stretch -linear-stretch <target_average value> 2.5
 <input-raster.tif> <stretched-raster.tif>

That is, you also have to indicate the target average value. Supposing you only have one band, a (not so elegant but working) way on Unix to find out the mean (saved in a variable $mean) is:

mean=$(gdalinfo -stats <input-raster.tif> |grep Mean|cut -f4 -d "="|sed 's/, StdDev//g')

Hope this helps!

0

I have used OpenEV from FWTools for that purpose. Open the image - apply LUT stretch - save image with original resolution into new image file. FWTools is pretty old but try if if still works for you. OpenEV is also available from OSGeo4W.

  • Thank you for your reply, but I am aware of OpenEV. I want to be able to do this from within QGIS, or with gdal (FWTools). I am trying to reduce the number of software packages I use, and eliminate the need of jumping in and out of software. – Ryan Garnett May 19 '14 at 13:46
  • Sorry, I did not understand that you was meaning just GDAL. FWTools, by its own words "includes OpenEV, GDAL, MapServer, PROJ.4 and OGDI as well as some supporting components" fwtools.maptools.org. – user30184 May 19 '14 at 17:57
  • My mistake. I will edit it the post – Ryan Garnett May 19 '14 at 18:02
  • 2
    Gdalinfo -stats computes statistics. Here is an example of the report: Metadata: STATISTICS_MAXIMUM=255 STATISTICS_MEAN=75.570955180556 STATISTICS_MINIMUM=1 STATISTICS_STDDEV=31.050844340168 By mean and stddev you can calculate the desired range and use that in gdal_translate -scale. Read the usage from gdal.org/gdal_translate.html. You will need a newer GDAL version than FWTools contains but you should find GDAL 1.10 from your QGIS 2.x installation and Gisinternals.com/sdk delivers nightly GDAL builds for Windows. – user30184 May 19 '14 at 19:11
  • 2
    If you re-scale your image with -scale option the new file will be permanently stretched. I have used the option only occasionally for making some 16-bit or 32-bit DEMs suitable for visual inspection. Often they are all too dark otherwise. – user30184 May 19 '14 at 19:47

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.