GDAL-RASTER-RGB-TO-PALETTE(1)

NAME
gdal-raster-rgb-to-palette - Convert a RGB image into a pseudo-color / paletted image.

Added in version 3.12.

SYNOPSIS

    Usage: gdal raster rgb-to-palette [OPTIONS] <INPUT> <OUTPUT>
    Convert a RGB image into a pseudo-color / paletted image.
    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)
    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 is allowed
                                                           Mutually exclusive with --append
      --append                                             Append as a subdataset to existing output
                                                           Mutually exclusive with --overwrite
      --color-count <COLOR-COUNT>                          Select the number of colors in the generated color table (default: 256)
      --color-map <COLOR-MAP>                              Color map filename
    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 rgb-to-palette computes an optimal pseudo-color table for a given RGB image using a median cut algorithm on a downsampled RGB histogram, unless a color table is provided with the --color-map option. Then it converts the image into a pseudo-colored image using the color table. This conversion utilizes Floyd-Steinberg dithering (error diffusion) to maximize output image visual quality.

This subcommand is also available as a potential step of gdal raster pipeline

  Standard options

-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

--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.

--overwrite
    Allow program to overwrite existing target file or dataset. Otherwise, by default, gdal errors out if the target file or dataset already exists.

--color-count <COLOR-COUNT>
    Select the number of colors in the generated color table. Defaults to 256. Must be between 2 and 256.

--color-map <FILENAME>
    Extract the color table from <FILENAME> instead of computing it. Can be used to have a consistent color table for multiple files. The <FILENAME> must be either a raster file in a GDAL supported format with a palette or a color file in a supported format (.txt, QGIS .qml, QGIS .qlr).

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.

NOTE: However this algorithm is not natively streaming compatible. Consequently a temporary dataset will be generated, which may cause significant processing time at opening.

EXAMPLES

  Example 1

Convert a TIFF file into a paletted PNG image

    $ gdal raster rgb-to-palette input.tif output.png

AUTHOR
Even Rouault <even.rouault@spatialys.com>

COPYRIGHT
1998-2025