Re: Implementing -scale functionality of gdal_translate

Sean Gillies
 

Hi,

Rasterio's rio-convert program can linearly scale pixels and apply offsets:

$ rio convert --help
Usage: rio convert [OPTIONS] INPUTS... OUTPUT

  Copy and convert raster datasets to other data types and formats.

  Data values may be linearly scaled when copying by using the --scale-ratio
  and --scale-offset options. Destination raster values are calculated as

    dst = scale_ratio * src + scale_offset

  For example, to scale uint16 data with an actual range of 0-4095 to 0-255
  as uint8:

    $ rio convert in16.tif out8.tif --dtype uint8 --scale-ratio 0.0625

  Format specific creation options may also be passed using --co. To tile a
  new GeoTIFF output file, do the following.

    --co tiled=true --co blockxsize=256 --co blockysize=256

  To compress it using the LZW method, add

    --co compress=LZW

Options:
  -o, --output PATH               Path to output file (optional alternative to
                                  a positional arg).
  -f, --format, --driver TEXT     Output format driver
  -t, --dtype [ubyte|uint8|uint16|int16|uint32|int32|float32|float64]
                                  Output data type.
  --scale-ratio FLOAT             Source to destination scaling ratio.
  --scale-offset FLOAT            Source to destination scaling offset.
  --rgb                           Set RGB photometric interpretation.
  --co, --profile NAME=VALUE      Driver specific creation options.See the
                                  documentation for the selected output driver
                                  for more information.
  --help                          Show this message and exit.

Different forms of scaling are possible if you use the Python API, numpy, and scikit-image.

Hope this helps,

On Fri, Jan 25, 2019 at 10:44 AM <linden.kyle@...> wrote:
Is there any way to replicate the -scale functionality of gdal_translate in Rasterio to scale the input pixels of a geotiff to a different range?



--
Sean Gillies

Join main@rasterio.groups.io to automatically receive all group messages.