- testing 3.12.3+dfsg-1
- unstable 3.12.3+dfsg-1
- experimental 3.13.0~beta1+dfsg-1~exp1
| GDAL-RASTER-SCALE(1) | GDAL | GDAL-RASTER-SCALE(1) |
NAME¶
gdal-raster-scale - Scale the values of the bands of a raster dataset
Added in version 3.11.
SYNOPSIS¶
Usage: gdal raster scale [OPTIONS] <INPUT> <OUTPUT> Scale the values of the bands of a raster dataset. Positional arguments:
-i, --input <INPUT> Input raster datasets [required]
-o, --output <OUTPUT> Output raster dataset [required] Common Options:
-h, --help Display help message and exit
--json-usage Display usage as JSON document and exit
--config <KEY>=<VALUE> Configuration option [may be repeated]
-q, --quiet Quiet mode (no progress bar or warning message) Options:
-f, --of, --format, --output-format <OUTPUT-FORMAT> Output format ("GDALG" allowed)
--co, --creation-option <KEY>=<VALUE> Creation option [may be repeated]
--overwrite Whether overwriting existing output dataset is allowed
Mutually exclusive with --append
--append Append as a subdataset to existing output
Mutually exclusive with --overwrite
--ot, --datatype, --output-data-type <OUTPUT-DATA-TYPE> Output data type. OUTPUT-DATA-TYPE=UInt8|Int8|UInt16|Int16|UInt32|Int32|UInt64|Int64|CInt16|CInt32|Float16|Float32|Float64|CFloat32|CFloat64
-b, --band <BAND> Select band to restrict the scaling (1-based index)
--src-min <SRC-MIN> Minimum value of the source range
--src-max <SRC-MAX> Maximum value of the source range
--dst-min <DST-MIN> Minimum value of the destination range
--dst-max <DST-MAX> Maximum value of the destination range
--exponent <EXPONENT> Exponent to apply non-linear scaling with a power function
--no-clip Do not clip input values to [srcmin, srcmax] Advanced Options:
--if, --input-format <INPUT-FORMAT> Input formats [may be repeated]
--oo, --open-option <KEY>=<VALUE> Open options [may be repeated]
DESCRIPTION¶
gdal raster scale can be used to rescale the input pixels values from the range --src-min to --src-max to the range --dst-min to --dst-max. It is also often necessary to reset the output datatype with the --ot switch. If omitted the output range is from the minimum value to the maximum value allowed for integer data types (for example from 0 to 255 for Byte output) or from 0 to 1 for floating-point data types. If omitted the input range is automatically computed from the source dataset. This may be a slow operation on a large source dataset, and if using it multiple times for several gdal_translate invocation, it might be beneficial to call gdal raster edit --stats {source_dataset} priorly to precompute statistics, for formats that support serializing statistics computations (GeoTIFF, VRT...) Source values are clipped to the range defined by srcmin and srcmax, unless --no-clip is set.
By default, the scaling is applied to all bands. It is possible to restrict it to a single band with --band and leave values of other bands unmodified.
This command is the reverse operation of gdal raster unscale.
This subcommand is also available as a potential step of gdal raster pipeline
GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET)¶
This program supports serializing the command line as a JSON file using the GDALG output format. The resulting file can then be opened as a raster dataset using the GDALG: GDAL Streamed Algorithm driver, and apply the specified pipeline in a on-the-fly / streamed way.
PROGRAM-SPECIFIC OPTIONS¶
- -b, --band <BAND>
- Index (starting at 1) of the band to which the scaling must be only applied.
- --dst-max <DSTMAX>
- Maximum value of the output range. This option must be used together with --dst-min.
- --dst-min <DSTMIN>
- Minimum value of the output range. This option must be used together with --dst-max.
- --exponent <EXPONENT>
- Apply non-linear scaling with a power function. exp_val is the
exponent of the power function (must be positive). This option must be
used with the --src-min / --src-max / --dst-min /
--dst-max options.
The scaled value Dst is calculated from the source value Src with the following formula:
{Dst} = \left( {Dst}_{max} - {Dst}_{min} \right) \times \operatorname{max} \left( 0, \operatorname{min} \left( 1, \left( \frac{{Src} - {Src}_{min}}{{Src}_{max}-{Src}_{min}} \right)^{exp\_val} \right) \right) + {Dst}_{min}
NOTE:
- --no-clip
- Disable clipping input values to the source range. Note that using this option with non-linear scaling with a non-integer exponent will cause input values lower than the minimum value of the source range to be mapped to not-a-number.
- --src-max <SRCMAX>
- Maximum value of the source range. If not specified, it will be calculated from the source dataset. This option must be used together with --src-min.
- --src-min <SRCMIN>
- Minimum value of the source range. If not specified, it will be calculated from the input dataset. This option must be used together with --src-max.
STANDARD OPTIONS¶
- --append
- Append input raster as a new subdataset to an existing output file. Only works with drivers that support adding subdatasets such as GTiff -- GeoTIFF File Format and GPKG -- GeoPackage raster This also creates the output dataset if it does not exist yet.
- --co, --creation-option <NAME>=<VALUE>
- Many formats have one or more optional creation options that can be used
to control particulars about the file created. For instance, the GeoTIFF
driver supports creation options to control compression, and whether the
file should be tiled.
May be repeated.
The creation options available vary by format driver, and some simple formats have no creation options at all. A list of options supported for a format can be listed with the --formats command line option but the documentation for the format is the definitive source of information on driver creation options. See Raster drivers format specific documentation for legal creation options for each format.
- --if, --input-format <format>
- Format/driver name to be attempted to open the input file(s). It is
generally not necessary to specify it, but it can be used to skip
automatic driver detection, when it fails to select the appropriate
driver. This option can be repeated several times to specify several
candidate drivers. Note that it does not force those drivers to open the
dataset. In particular, some drivers have requirements on file extensions.
May be repeated.
- --oo, --open-option <NAME>=<VALUE>
- Dataset open option (format specific).
May be repeated.
- -f, --of, --format, --output-format <OUTPUT-FORMAT>
- Which output raster format to use. Allowed values may be given by gdal --formats | grep raster | grep rw | sort
- --ot, --datatype, --output-data-type <OUTPUT-DATA-TYPE>
- Output data type among Byte, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, CInt16, CInt32, Float32, Float64, CFloat32, CFloat64.
- --overwrite
- Allow program to overwrite existing target file or dataset. Otherwise, by default, gdal errors out if the target file or dataset already exists.
RETURN STATUS CODE¶
The program returns status code 0 in case of success, and non-zero in case of error (non-blocking errors emitted as warnings are considered as a successful execution).
EXAMPLES¶
Example 1: Rescale linearly values of a UInt16 dataset from [0,4095] to a Byte dataset [0,255]¶
$ gdal raster scale --datatype Byte --src-min 0 --src-max 4095 uint16.tif byte.tif --overwrite
AUTHOR¶
Even Rouault <even.rouault@spatialys.com>
COPYRIGHT¶
1998-2026
| April 15, 2026 |