[gdal-dev] Gdal_translate and -scale with non-Byte output

Rahkonen Jukka (MML) jukka.rahkonen at maanmittauslaitos.fi
Fri Jun 28 03:42:06 PDT 2019


Hi,

I was reading https://gis.stackexchange.com/questions/247767/performing-histogram-streching-using-gdal-translate and made some tests and now I feel that gdal_translate with -scale does not handle well some use cases with non-Byte output.

The syntax is -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."

User can omit a) just the destination range or b) both the source range and the destination range but it is not possible to omit just the source range. This means that if the output is for example Int32 then user cannot let GDAL to detect the input range automatically. Or they can but then the output range is set to 0-255 which is not so good for Int32.

I do not really know how big problem this is or what to do for improving current behavior. Only idea that came into my mind was introduce two new keywords "srs_auto" and "dst_auto". "srs_auto" would do the same than omitting input range, so compute the range from the source data. "dst_auto" would set the range into min-max of the valid values for each output datatype.
BTW is seems that -scale without ranges does not always work quite as documented. The default output range in this test did not stay between 0 and 255.

gdal_translate -of GTiff -ot Int32 -scale base.tif scaletest.tif
gdalinfo scaletest.tif -stats
...
STATISTICS_MAXIMUM=259
STATISTICS_MEAN=109.94244718749
STATISTICS_MINIMUM=-6

-Jukka Rahkonen-



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190628/873093e3/attachment.html>


More information about the gdal-dev mailing list