RGB2PCT(1)
β¨ rgb2pct(1) β¨
okay so bestie, listen π this one is rgb2pct, and it lives in the GDAL family of utilities. She's giving "glow-up for your images" energy and honestly? we're obsessed.
NAME
rgb2pct β Convert a 24bit RGB image to 8bit paletted. π
SYNOPSIS
rgb2pct [--help] [--help-general] [--creation-option OPTION]
[-n colors | -pct palette_file] [-of format] <source_file> <dest_file>
DESCRIPTION
So here's the tea π«: this utility will compute an optimal pseudo-color table for a given RGB image using a median cut algorithm on a downsampled RGB histogram. Like, it's doing MATH on your colors, and the math is cute. Then it converts the image into a pseudo-colored image using that color table. β¨
And the conversion? It utilizes Floyd-Steinberg dithering (that's error diffusion, iykyk) to maximize output image visual quality. Basically it makes your 8bit look way better than 8bit has any right to look. periodt. π
NOTE: rgb2pct is a Python utility, and is only available if GDAL Python bindings are available. no bindings, no vibes, no service. π
TIP: Equivalent in new"gdal"command line interface: Seegdal raster rgb-to-palette.
β¨ OPTIONS β¨
--helpβ Show this help message and exit. the classic. π--help-generalβ Gives a brief usage message for the generic GDAL commandline options and exit. it's the general-vibes help, not the specific-vibes help π¦-n<color>β Select the number of colors in the generated color table. Defaults to256. Must be between2and256. so like, don't get weird with it. π--creation-optionOPTIONβ Optional creation parameters for the GeoTIFF driver, for example"COMPRESS=LZW". Can be specified multiple times. stack 'em up bestie π₯-pct<palette_file>β Extract the color table from<palette_file>instead of computing it. Can be used to have a consistent color table for multiple files. The<palette_file>must be either a raster file in a GDAL supported format with a palette or a color file in a supported format (txt,qml,qlr). consistent palette across your whole folder = main character energy π-of<format>β Select the output format. If not specified, the format is guessed from the extension. Use the short format name. Only output formats supporting pseudo-color tables should be used. don't set yourself up like that π<source_file>β The input RGB file. the before picture πΈ<dest_file>β The output pseudo-colored file that will be created. the after picture β¨
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). so 0 = slay, anything else = π¨
EXAMPLE
If it is desired to hand create the palette, likely the simplest text format is the GDAL VRT format. In the following example a VRT was created in a text editor with a small 4 color palette with the RGBA colors 238/238/238/255, 237/237/237/255, 236/236/236/255 and 229/229/229/255. look at her, little handcrafted palette, an icon π
$ rgb2pct -pct palette.vrt rgb.tif pseudo-colored.tif
$ more < palette.vrt
<VRTDataset rasterXSize="226" rasterYSize="271">
<VRTRasterBand dataType="Byte" band="1">
<ColorInterp>Palette</ColorInterp>
<ColorTable>
<Entry c1="238" c2="238" c3="238" c4="255"/>
<Entry c1="237" c2="237" c3="237" c4="255"/>
<Entry c1="236" c2="236" c3="236" c4="255"/>
<Entry c1="229" c2="229" c3="229" c4="255"/>
</ColorTable>
</VRTRasterBand>
</VRTDataset>
AUTHOR
Frank Warmerdam <warmerdam@pobox.com> π«Ά
COPYRIGHT
1998-2026
and that's the whole page bestie, no cap π this GDAL manual page is dated Aug 18, 2026, and yeah she's still going strong. rgb2pct(1) β ate and left no crumbs. πβ
π¦ where this page comes from
- alpine 3.24: gdal-doc 3.13.3-r0 Β· MIT
- arch rolling: gdal 3.13.3-6 Β· MIT
- ubuntu stonking: gdal-bin 3.13.3+dfsg-1ubuntu4 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms