When using the -rescale option of gdal_translate, the output file does not have the scale or offset values stored in its metadata and therefore cannot be automatically unscaled when read. Is this intended behaviour or a bug?


I would consider using GDAL VRT as outputformat which leaves the image untouched and creates only XML file that describes how to read the source data. Delete the VRT file and you have unscaled your image.

You can also edit the result tiff with gdal_edit.py utility http://www.gdal.org/gdal_edit.html. Since GDAL 2.2 it has options -scale and -offset. Command is used as

gdal_edit -scale 1.2 -offset 12 metadata.tif

The -scale option of gdal_translate does not take input as scale and offset but as documented

-scale [src_min src_max [dst_min dst_max]]: Rescale the input pixels values from the range src_min to src_max to the range dst_min to dst_max. If omitted the output range is 0 to 255. If omitted the input range is automatically computed from the source data. Before GDAL 1.11, it can be specified only once, and in that case, it applies to all bands of the output dataset. Starting with GDAL 1.11, -scale can be repeated several times (if specified only once, it also applies to all bands of the output dataset), so as to specify per band parameters. It is also possible to use the "-scale_bn" syntax where bn is a band number (e.g. "-scale_2" for the 2nd band of the output dataset) to specify the parameters of one or several specific bands.

In simple case when all bands are scaled with the same settings it should be possible to define backward conversion with -scale and -offset but not when bands are stretched with different values. Neither would if work with exponential scaling with -exponent.

I may be wrong but I believe that your idea would not generally work. Easiest solution would be to do a virtual scaling with VRT file.

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.