[gdal-dev] Gdal_translate and -scale with non-Byte output
even.rouault at spatialys.com
Fri Jun 28 06:22:54 PDT 2019
On vendredi 28 juin 2019 10:42:06 CEST Rahkonen Jukka (MML) wrote:
> I was reading
> ng-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
Reasonable proposal. Could be worth an enhancement ticket with a "good first
issue" label to attract contributors :-)
> 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.
I see that if the min/max of the source is not already known, we compute it
but with approximation enabled. That's the likely reason (or if statistics
have been previously computed in an approximated way). As the src and dst min/
max values of -scale are used to compute an offset value and a scaling factor,
no clamping to the implied or specified dst_min/dst_max can be done (except
due to the validty range of the data type itself).
Spatialys - Geospatial professional services
More information about the gdal-dev