{
    "mode": "man",
    "parameter": "pnmcolormap",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pnmcolormap/1/json",
    "generated": "2026-08-26T20:30:59Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "pnmcolormap - create quantization color map for a Netpbm image\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "pnmcolormap",
                    "content": "[-center|-meancolor|-meanpixel]\n\n[-spreadbrightness|-spreadluminosity]\n\n[-splitpixelct|-splitcolorct|-splitspread]\n\n[-sort]\n\n[-square]\n\n[-verbose]\n\n[-debug]\n\nncolors|all\n\n[pnmfile]\n\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\npnmcolormap  reads  a PNM or PAM image as input, chooses ncolors colors to best represent the\nimage and writes a PNM color map defining them as output.  A PAM image may  actually  contain\ntuples  of  any  kind,  but pnmcolormap's concept of the tuple values that best represent the\nones present in the image may not make sense if the tuple type isn't RGB or  GRAYSCALE.   The\ndesign of the program, and the rest of this manual, assumes the tuples represent colors.\n\nYou  can  use this map as input to pnmremap on the same input image to quantize the colors in\nthat image, I.e. produce a similar image with fewer colors.  pnmquant does both  the  pnmcol‐\normap and pnmremap steps for you.\n\nA  PNM  colormap  is  a  PNM image of any dimensions that contains at least one pixel of each\ncolor in the set of colors it represents.  The ones pnmcolormap generates  have  exactly  one\npixel of each color, except where padding is necessary with the -square option.\n\nThe quantization method is Heckbert's \"median cut\".  See \u001b]8;;#quant\u001b\\QUANTIZATION METHOD\u001b]8;;\u001b\\ .\n\nThe  output image is of the same format (PBM, PGM, PPM, PAM) as the input image.  Note that a\ncolormap of a PBM image is not very interesting.\n\nThe colormap generally has the same maxval as the input image, but pnmcolormap may reduce  it\nif there are too many colors in the input, as part of its quantization algorithm.\n\npnmcolormap works on a multi-image input stream.  In that case, it produces one colormap that\napplies  to  all of the colors in all of the input images.  All the images must have the same\nformat, depth, and maxval (but may have different height and width).  This is useful  if  you\nneed  to  quantize  a bunch of images that will form a movie or otherwise be used together --\nyou generally want them all to draw from the same palette, whereas computing a colormap sepa‐\nrately from each image would make the same color in two images map to different colors.   Be‐\nfore Netpbm 10.31 (December 2005), pnmcolormap ignored any image after the first.\n\nIf  you  want to create a colormap without basing it on the colors in an input image, pamseq,\nppmmake, and pamcat can be useful.\n\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "The single parameter, which is required, is the number of colors you want in the output  col‐\normap.   pnmcolormap  may  produce a color map with slightly fewer colors than that.  You may\nspecify all to get a colormap of every color in the input image (no quantization).  When  you\nspecify  all,  the function is essentially the same as that of ppmhist -map.  ppmhist is much\nolder.\n\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "In addition to the options common to all programs based on libnetpbm  (most  notably  -quiet,\nsee \u001b]8;;index.html#commonoptions\u001b\\ Common Options\u001b]8;;\u001b\\ ), pnmcolormap recognizes the following command line options:\n\nAll  options can be abbreviated to their shortest unique prefix.  You may use two hyphens in‐\nstead of one to designate an option.  You may use either white space or an  equals  sign  be‐\ntween an option name and its value.\n\n\n",
            "subsections": [
                {
                    "name": "-sort",
                    "content": "then the green, then the blue in ascending order.  This is an insertion sort, so it is\nnot very fast on large colormaps.  Sorting is useful because it allows you to  compare\ntwo sets of colors.\n\n"
                },
                {
                    "name": "-square",
                    "content": "By  default,  pnmcolormap  produces as the color map a PPM image with one row and with\none column for each color in the colormap.  This option causes pnmcolormap instead  to\nproduce  a  PPM  image that is within one row or column of being square, with the last\npixel duplicated as necessary to create a number of pixels which is  such  an  almost-\nperfect square.\n\n"
                },
                {
                    "name": "-verbose",
                    "content": "This option causes pnmcolormap to display messages to Standard Error about the quanti‐\nzation..TP -center\n\n"
                },
                {
                    "name": "-debug",
                    "content": "workings.\n\n"
                },
                {
                    "name": "-center",
                    "content": ""
                },
                {
                    "name": "-meancolor",
                    "content": ""
                },
                {
                    "name": "-meanpixel",
                    "content": ""
                },
                {
                    "name": "-spreadbrightness",
                    "content": ""
                },
                {
                    "name": "-spreadluminosity",
                    "content": ""
                },
                {
                    "name": "-splitpixelct",
                    "content": ""
                },
                {
                    "name": "-splitcolorct",
                    "content": ""
                },
                {
                    "name": "-splitspread",
                    "content": "These options control the quantization algorithm.  See \u001b]8;;#quant\u001b\\QUANTIZATION METHOD\u001b]8;;\u001b\\ .\n\n\n\n\n"
                }
            ]
        },
        "QUANTIZATION METHOD": {
            "content": "A quantization method is a way to choose which colors, being fewer in number than in the  in‐\nput, you want in the output.  pnmcolormap uses Heckbert's \"median cut\" quantization method.\n\nThis  method involves separating all the colors into \"boxes,\" each holding colors that repre‐\nsent about the same number of pixels.  You start with one box and split boxes  in  two  until\nthe  number  of  boxes is the same as the number of colors you want in the output, and choose\none color to represent each box.\n\nThere are three ways pnmcolormap can choose the box to split in\neach step:\n\n\n•      Split the box containing the most pixels.  This is the default,\nand you can select it explicitly with option -splitpixelct.\n\n•      Split the box containing the most colors.  This appears to be useful\nfor academic purposes only.  Select this with option\n-splitcolorct.\n\n•      Split the box containing the largest color spread.  Select this\nwith option -splitspread.  This can produce a better result for\nsmall details with colors not found elsewhere in the image.\n\n",
            "subsections": [
                {
                    "name": "-splitpixelct",
                    "content": "in Netpbm 10.88 (September 2019).  Before that, pnmcolormap always\nsplits the box containing the most pixels.\n\n\nWhen you split a box, you do it so each sub-box has the same number  of  pixels  (except  one\nsub-box  has  more if the full box has an odd number), with the 'greatest' pixels in one sub-\nbox and the 'least' pixels in the other.  \"Greater,\"  for  a  particular  box,  means  it  is\nbrighter  in the color component (red, green, blue) which has the largest spread in that box.\npnmcolormap gives you two ways to define \"largest spread.\": 1) largest spread of  brightness;\n2)  largest spread of contribution to the luminosity of the color.  E.g. red is weighted much\nmore than blue.  Select among these with the -spreadbrightness and -spreadluminosity options.\nThe default is -spreadbrightness.  Where there are multiple colors of the  median  magnitude,\nthey are distributed arbitrarily among between the subboxes.\n\nThis  arbitrary distribution is repeatable, though, for a given Netpbm version -- every invo‐\ncation of pnmcolormap generates the same color map.  Before Netpbm  11.03  (June  2023),  the\ndistribution would depend upon what the system's qsort function does with multiple equal val‐\nues, so pnmcolormap may produce slightly different results on different systems.\n\npnmcolormap provides three ways of choosing a color to represent a box: 1) the center color -\nthe  color  halfway between the greatest and least colors in the box, using the above defini‐\ntion of \"greater\"; 2) the mean of the colors (each component averaged separately  by  bright‐\nness) in the box; 3) the mean weighted by the number of pixels of a color in the image.\n\nSelect  among  these  with  the  -center, -meancolor, and -meanpixel options.  The default is"
                },
                {
                    "name": "-center",
                    "content": "Note that in all three methods, there may be colors in the output which do not appear in  the\ninput at all.\n\nAlso  note that the color chosen to represent the colors in Box A the best may also represent\na color in Box B better than the color chosen to represent the colors  in  Box  B  the  best.\nThis  is true for various measures of goodness of representation of one color by another.  In\nparticular, if you use pnmremap to map the colors in the very image that you used  to  create\nthe color map to the colors in that colormap, the colors in Box B will often map to the color\npnmcolormap chose to represent some other box and in fact the color pnmcolormap chose to rep‐\nresent Box B may not appear in the pnmremap output at all.\n\n\n"
                }
            ]
        },
        "REFERENCES": {
            "content": "\"Color  Image  Quantization for Frame Buffer Display\" by Paul Heckbert, SIGGRAPH '82 Proceed‐\nings, page 297.\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "pnmremap(1), pnmquant(1), ppmquantall(1),  pamgetcolor(1),  pamdepth(1),  ppmdither(1),  pam‐\nseq(1), ppmmake(1), pamcat(1), ppm(1)\n\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "Before Netpbm 10.15 (April 2003), pnmcolormap used a lot more memory for large images because\nit  kept the entire input image in memory.  Now, it processes it a row at a time, but because\nit sometimes must make multiple passes through the image, it first copies the  input  into  a\ntemporary seekable file if it is not already in a seekable file.\n\npnmcolormap  first  appeared  in  Netpbm  9.23 (January 2002).  Before that, its function was\navailable only as part of the function of pnmquant (which was derived from the much older pp‐\nmquant).  Color quantization really has two main subfunctions, so Netpbm 9.23  split  it  out\ninto  two  separate programs: pnmcolormap and pnmremap and then Netpbm 9.24 replaced pnmquant\nwith a program that simply calls pnmcolormap and pnmremap.\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright (C) 1989, 1991 by Jef Poskanzer.\n",
            "subsections": []
        },
        "DOCUMENT SOURCE": {
            "content": "This manual page was generated by the Netpbm tool 'makeman' from  HTML  source.   The  master\ndocumentation is at\n\nhttp://netpbm.sourceforge.net/doc/pnmcolormap.html\n\nnetpbm documentation                      21 February 2023                Pnmcolormap User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pnmcolormap - create quantization color map for a Netpbm image",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "then the green, then the blue in ascending order. This is an insertion sort, so it is not very fast on large colormaps. Sorting is useful because it allows you to compare two sets of colors."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "By default, pnmcolormap produces as the color map a PPM image with one row and with one column for each color in the colormap. This option causes pnmcolormap instead to produce a PPM image that is within one row or column of being square, with the last pixel duplicated as necessary to create a number of pixels which is such an almost- perfect square."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pnmcolormap to display messages to Standard Error about the quanti‐ zation..TP -center"
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "workings."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "These options control the quantization algorithm. See \u001b]8;;#quant\u001b\\QUANTIZATION METHOD\u001b]8;;\u001b\\ ."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "pnmremap",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnmremap/1/json"
        },
        {
            "name": "pnmquant",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnmquant/1/json"
        },
        {
            "name": "ppmquantall",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmquantall/1/json"
        },
        {
            "name": "pamgetcolor",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamgetcolor/1/json"
        },
        {
            "name": "pamdepth",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamdepth/1/json"
        },
        {
            "name": "ppmdither",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmdither/1/json"
        },
        {
            "name": "seq",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/seq/1/json"
        },
        {
            "name": "ppmmake",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmmake/1/json"
        },
        {
            "name": "pamcat",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamcat/1/json"
        },
        {
            "name": "ppm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppm/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Create quantization color map for a PNM image.",
        "examples": [
            {
                "description": "Generate an image using only `n_colors` or less colors as close as possible to the input image",
                "command": "pnmcolormap {{n_colors}} {{path/to/input.pnm}} > {{path/to/output.ppm}}"
            },
            {
                "description": "Use the splitspread strategy for determining the output colors, possibly producing a better result for images with small details",
                "command": "pnmcolormap {{-splits|-splitspread}} {{n_colors}} {{path/to/input.pnm}} > {{path/to/output.ppm}}"
            },
            {
                "description": "Sort the resulting colormap, which is useful for comparing colormaps",
                "command": "pnmcolormap {{-so|-sort}} {{path/to/input.pnm}} > {{path/to/output.ppm}}"
            }
        ]
    }
}