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 either a  raster  file  in  a
26              GDAL  supported  format with a palette or a color file in a sup‐
27              ported format (txt, qml, qlr).
28
29       -of <format>
30              Select the output format. Starting with GDAL 2.3, if not  speci‐
31              fied,  the  format is guessed from the extension (previously was
32              GTiff). Use the short format name. Only output formats  support‐
33              ing pseudo-color tables should be used.
34
35       <source_file>
36              The input RGB file.
37
38       <dest_file>
39              The output pseudo-colored file that will be created.
40
41       NOTE:  rgb2pct.py  is  a  Python script, and will only work if GDAL was
42       built with Python support.
43

EXAMPLE

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

AUTHOR

65       Frank Warmerdam <warmerdam@pobox.com>
66
68       1998-2022
69
70
71
72
73                                 Sep 02, 2022                       RGB2PCT(1)
Impressum