{
    "mode": "man",
    "parameter": "pgmtoppm",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pgmtoppm/1/json",
    "generated": "2026-09-02T21:40:11Z",
    "synopsis": "pgmtoppm [-black=colorspec1] [-white=colorspec2]\n[pgmfile]  pgmtoppm  -map=filename  [pgmfile]  pgmtoppm  colorspec [pgmfile] pgmtoppm color‐\nspec1-colorspec2 [pgmfile]\nMinimum unique abbreviation of option is acceptable.  You may use double hyphens  instead  of\nsingle hyphen to denote options.  You may use white space in place of the equals sign to sep‐\narate an option name from its value.",
    "sections": {
        "NAME": {
            "content": "pgmtoppm - colorize a PGM (grayscale) image into a PPM (color) image\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "pgmtoppm [-black=colorspec1] [-white=colorspec2]\n[pgmfile]  pgmtoppm  -map=filename  [pgmfile]  pgmtoppm  colorspec [pgmfile] pgmtoppm color‐\nspec1-colorspec2 [pgmfile]\n\nMinimum unique abbreviation of option is acceptable.  You may use double hyphens  instead  of\nsingle hyphen to denote options.  You may use white space in place of the equals sign to sep‐\narate an option name from its value.\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\nIf all you want to do is convert PGM to PPM, keeping the same gray pixels,\nyou may not need to.  All Netpbm programs that expect PPM input also\nrecognize PGM.  And if you must have a PPM file, use ppmtoppm\ninstead.  It is more efficient and easier to use.\n\npgmtoppm  reads  a  PGM  as input and produces a PPM file as output with a specific color as‐\nsigned to each gray value in the input.\n\nYou can specify the color in the output to which black in the input maps,\nand the color to which white maps.  All the gray values in between map\nlinearly (across a three dimensional space) to colors between the black and\nwhite colors you specify.\n\nUse the -black and -white options for this.  For historical\nreasons, you can alternatively use a non-option argument to specify the\ncolors.  If you do that, pgmtoppm interprets the color argument\nlike this: if the argument takes the form black-white,\nit has the effect of -black=black -white=white\nIf instead there is no hyphen in the color argument, it has the effect of\n-white=colorargument.\n\nBecause of the historical syntax, it is not possible to let both\n-black and -white default (but you shouldn't want to --\nsee below for advice on making such a null conversion).\n\n\nYou can alternatively specify an entire colormap with the -map option.\n\n\nA more direct way to specify a particular color to replace each particular gray level  is  to\nuse  pamlookup.  You make an index file that explicitly associates a color with each possible\ngray level.\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\\ ), pgmtoppm recognizes the following command line options:\n\n\n\n",
            "subsections": [
                {
                    "name": "-black=_",
                    "content": "The  program  maps black pixels in the input to this color in the output.  The default\nis black.\n\nSpecify the color (color) as described  for  the  \u001b]8;;libnetpbmimage.html#colorname\u001b\\argument of the pnmparsecolor() li‐\nbrary routine\u001b]8;;\u001b\\ .\n\nYou cannot specify this together with -map.\n\nThis option was new in Netpbm 10.97 (December 2021).  Before that,\nuse the color argument.\n\n"
                },
                {
                    "name": "-white=_",
                    "content": "The  program  maps white pixels in the input to this color in the output.  The default\nis white.\n\nSpecify the color (color) as described  for  the  \u001b]8;;libnetpbmimage.html#colorname\u001b\\argument of the pnmparsecolor() li‐\nbrary routine\u001b]8;;\u001b\\ .\n\nYou cannot specify this together with -map.\n\nThis option was new in Netpbm 10.97 (December 2021).  Before that,\nuse the color argument.\n\n"
                },
                {
                    "name": "-map=_",
                    "content": "This option specifies a complete mapping of gray values in the input to\ncolor values in the output.  The map file (named filename) is just\na ppm file; it can be any shape, all that matters is the colors in\nit and their order.  In this case, black gets mapped into the first color\nin the map file, and white gets mapped to the last and gray values in\nbetween are mapped linearly onto the sequence of colors in between.  The\nmaxval of the output image is the maxval of the map image.\n\n\n\n\n"
                }
            ]
        },
        "NOTE - MAXVAL": {
            "content": "When  you  don't use -map, the \"maxval,\" or depth, of the output image is the same as that of\nthe input image.  The maxval affects the color resolution, which may cause  quantization  er‐\nrors you don't anticipate in your output.  For example, you have a simple black and white im‐\nage  as a PGM with maxval 1.  Run this image through pgmtoppm 0f/00/00 to try to make the im‐\nage black and faint red.  Because the output image will also have maxval 1, there is no  such\nthing  as  faint  red.   It has to be either full-on red or black.  pgmtoppm rounds the color\n0f/00/00 down to black, and you get an output image that is nothing but black.\n\nThe fix is easy: Pass the input through pamdepth on the way into  pgmtoppm  to  increase  its\ndepth to something that would give you the resolution you need to get your desired color.  In\nthis  case, pamdepth 16 would do it.  Or spare yourself the unnecessary thinking and just say\npamdepth 255.\n\nPBM input is a special case.  While you might think this would be equivalent to  a  PGM  with\nmaxval  1  since  only two gray levels are necessary to represent a PBM image, pgmtoppm, like\nall Netpbm programs, in fact treats it as a maxval of 255.\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ppmtoppm(1), pamdepth(1), rgb3toppm(1), ppmtopgm(1), ppmtorgb3(1), ppm(1), pgm(1)\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright (C) 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/pgmtoppm.html\n\nnetpbm documentation                       02 October 2021                   Pgmtoppm User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pgmtoppm - colorize a PGM (grayscale) image into a PPM (color) image",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "The program maps black pixels in the input to this color in the output. The default is black. Specify the color (color) as described for the \u001b]8;;libnetpbmimage.html#colorname\u001b\\argument of the pnmparsecolor() li‐ brary routine\u001b]8;;\u001b\\ . You cannot specify this together with -map. This option was new in Netpbm 10.97 (December 2021). Before that, use the color argument."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "The program maps white pixels in the input to this color in the output. The default is white. Specify the color (color) as described for the \u001b]8;;libnetpbmimage.html#colorname\u001b\\argument of the pnmparsecolor() li‐ brary routine\u001b]8;;\u001b\\ . You cannot specify this together with -map. This option was new in Netpbm 10.97 (December 2021). Before that, use the color argument."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option specifies a complete mapping of gray values in the input to color values in the output. The map file (named filename) is just a ppm file; it can be any shape, all that matters is the colors in it and their order. In this case, black gets mapped into the first color in the map file, and white gets mapped to the last and gray values in between are mapped linearly onto the sequence of colors in between. The maxval of the output image is the maxval of the map image."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "ppmtoppm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmtoppm/1/json"
        },
        {
            "name": "pamdepth",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamdepth/1/json"
        },
        {
            "name": "rgb3toppm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/rgb3toppm/1/json"
        },
        {
            "name": "ppmtopgm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmtopgm/1/json"
        },
        {
            "name": "ppmtorgb3",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmtorgb3/1/json"
        },
        {
            "name": "ppm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppm/1/json"
        },
        {
            "name": "pgm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pgm/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Colorize a PGM image.",
        "examples": [
            {
                "description": "Map all greyscale values of the input image to all colors between the two specified colors",
                "command": "pgmtoppm {{-b|-black}} {{red}} {{-w|-white}} {{blue}} {{path/to/input.pgm}} > {{path/to/output.ppm}}"
            },
            {
                "description": "Map all greyscale values of the input image to colors according to the specified colormap",
                "command": "pgmtoppm {{-m|-map}} {{path/to/colormap.ppm}} {{path/to/input.pgm}} > {{path/to/output.ppm}}"
            }
        ]
    }
}