I have some data with Int16 bands in HDF format.

I want to convert this to Byte bands in GeoTIFF format.

The data range for the Int16 is -2000 to 12000, so I want to map this to the Byte range 0 to 255.

How do I do this with GDAL tools? (if it is possible) Otherwise how can I write a Python script to do this.

2 Answers 2


I am not sure if you are aware of the -scale feature of the gdaltranslate tool. it might be just what you are looking for. It defaults to 0-255 and the min and maxx of your rasters. You should also set the null values before using this.

You might want to specify the output as type Byte just to be sure -ot "Byte"

hope this helps, :)

Edit: I always like to include helpful links: http://www.gdal.org/gdal_translate.html

  • You're very welcome.
    – s_a
    Sep 14, 2012 at 12:47

What you want to do is called Normalization and the general formula is :

Normalization formula


  • In = New Value
  • I = Present Value
  • Min= The minimum present value
  • Max = The maximum present value
  • newMin/newMax = the desired Min/Man (in your case 0 and 255)

You can use use a combination of gdal/python/numpy to open hdf datasets and perform cell calculations based on the above formula (but it's not as quite straightforward as it it with a eg: a geotiff file; You can find a starting script now how to load the subdatasets here)

  • Thanks for the info. I will see if I can write a script for this.
    – ljbade
    Sep 13, 2012 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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