RGB2PCT(1)
π NAME π
rgb2pct β and yes bestie, this is straight out of the GDAL manual, section 1, we're fancy β it converts a 24bit RGB image to 8bit paletted. That's the whole job. She takes your chunky true-colour pic and gives you a slim little palette queen back. π
β¨ SYNOPSIS β¨
rgb2pct.py [-n colors | -pct palette_file] [-of format] <source_file> <dest_file>
π¦ DESCRIPTION π¦
Okay so here's the tea β β this utility computes an optimal pseudo-color table for whatever RGB image you hand it, and it does that with a median cut algorithm running over a downsampled RGB histogram. Very demure, very efficient, no cap.
Then it flips your image into a pseudo-colored image using that color table. And the conversion? It uses Floyd-Steinberg dithering (error diffusion) to maximize output image visual quality. Like, she's literally diffusing the errors so your gradients don't look crusty. Iconic behavior honestly. π
π the options, one by one π
-n<color> β picks how many colors go in the generated color table. Defaults to256. Must be between2and256β no, you cannot have 1 color, and no, you cannot have 300. Boundaries exist for a reason bestie. π-pct<palette_file> β yoinks the color table out of <palette_file> instead of computing a fresh one. Super useful when you want a consistent color table across multiple files (matching vibes across the whole feed, yk?). The <palette_file> has to be either a raster file in a GDAL supported format with a palette, or a color file in a supported format (txt,qml,qlr). No random PNGs, she has standards. π§-of<format> β sets the output format. Starting with GDAL2.3, if you don't specify it, the format is guessed from the extension (previously wasGTiff). Use the short format name. And only output formats supporting pseudo-color tables should be used β don't set her up to fail. π«Ά- <source_file> β the input RGB file. Your raw material. β¨
- <dest_file> β the output pseudo-colored file that will be created. Your glow-up result. π
NOTE: rgb2pct.py is a Python script, and will only work if GDAL was built with Python support. Fr fr, if your GDAL skipped Python, this whole thing is a no-op and you'll be sad. Check first. π
π EXAMPLE π
So if you wanna hand-create the palette β and honestly the simplest text format for that is likely the GDAL VRT format β here's the move. 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.
rgb2pct.py -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>
Four whole colors. Minimalist. Lowkey obsessed. π¦
π AUTHOR π
Frank Warmerdam <warmerdam@pobox.com> β the legend himself, respect on his name. π«‘
πΈ COPYRIGHT πΈ
1998-2026
And that's the page, bestie π β this lil artifact is dated Jan 08, 2026 and lives at the bottom of the RGB2PCT(1) manual like a little signature. Go make some palettes. Mwah. πβ¨
π¦ where this page comes from
- epel 9: gdal3.4-python-tools 3.4.3-5.el9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms