1RGB2PCT(1)                           GDAL                           RGB2PCT(1)
2
3
4

NAME

6       rgb2pct - Convert a 24bit RGB image to 8bit paletted.
7

SYNOPSIS

9          rgb2pct.py [-n colors | -pct palette_file] [-of format] <source_file> <dest_file>
10

DESCRIPTION

12       This utility will compute an optimal pseudo-color table for a given RGB
13       image using a median cut algorithm  on  a  downsampled  RGB  histogram.
14       Then  it converts the image into a pseudo-colored image using the color
15       table.  This conversion utilizes Floyd-Steinberg dithering (error  dif‐
16       fusion) to maximize output image visual quality.
17
18       -n <color>
19              Select  the  number of colors in the generated color table.  De‐
20              faults to 256.  Must be between 2 and 256.
21
22       -pct <palette_file>
23              Extract the color table from <palette_file> instead of computing
24              it.  Can  be  used to have a consistent color table for multiple
25              files.  The<palette_file> must be a raster file in a  GDAL  sup‐
26              ported format with a palette.
27
28       -of <format>
29              Select  the output format. Starting with GDAL 2.3, if not speci‐
30              fied, the format is guessed from the extension  (previously  was
31              GTiff).  Use the short format name. Only output formats support‐
32              ing pseudo-color tables should be used.
33
34       <source_file>
35              The input RGB file.
36
37       <dest_file>
38              The output pseudo-colored file that will be created.
39
40       NOTE: rgb2pct.py is a Python script, and will only  work  if  GDAL  was
41       built with Python support.
42

EXAMPLE

44       If  it  is desired to hand create the palette, likely the simplest text
45       format is the GDAL VRT format.  In the following example a VRT was cre‐
46       ated in a text editor with a small 4 color palette with the RGBA colors
47       238/238/238/255, 237/237/237/255, 236/236/236/255 and 229/229/229/255.
48
49          % rgb2pct.py -pct palette.vrt rgb.tif pseudo-colored.tif
50          % more < palette.vrt
51          <VRTDataset rasterXSize="226" rasterYSize="271">
52              <VRTRasterBand dataType="Byte" band="1">
53                  <ColorInterp>Palette</ColorInterp>
54                  <ColorTable>
55                  <Entry c1="238" c2="238" c3="238" c4="255"/>
56                  <Entry c1="237" c2="237" c3="237" c4="255"/>
57                  <Entry c1="236" c2="236" c3="236" c4="255"/>
58                  <Entry c1="229" c2="229" c3="229" c4="255"/>
59                  </ColorTable>
60              </VRTRasterBand>
61          </VRTDataset>
62

AUTHOR

64       Frank Warmerdam <warmerdam@pobox.com>
65
67       1998-2021
68
69
70
71
72                                 Mar 24, 2021                       RGB2PCT(1)
Impressum