{
    "mode": "man",
    "parameter": "pambackground",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pambackground/1/json",
    "generated": "2026-09-03T23:20:00Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "pambackground - create a mask of the background area of an image\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "pambackground",
                    "content": "[netpbmfile]\n\n[-verbose]\n\nMinimum  unique  abbreviations of options are acceptable.  You may use double hyphens instead\nof single hyphen to denote options.  You may use white space in place of the equals  sign  to\nseparate an option name from its value.\n\n\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\npambackground  reads  a  PNM  or PAM image as input.  It generates as output a PAM image that\nidentifies the background area of the image (a mask).\n\nTo identify the background, pambackground assumes the image is a  foreground  image,  smaller\nthan the total image size, placed over a single-color background.  It assumes that foreground\nimage  is  solid  --  it does not have holes through which the background can be seen.  So in\nspecific, pambackground first identifies the background color, then finds all contiguous pix‐\nels of that color in regions touching any edge of the image.  Think of it as starting at each\nof the four edges and moving inward and spreading out as far as possible until it hits pixels\nof another color (the foreground image).\n\npambackground identifies the background color as follows: If any 3 corners of the  image  are\nthe  same  color, that's the background color.  If not, but 2 corners are the same color, the\nbackground color is the color of a pair of identically colored corners in this  priority  or‐\nder:  top,  right, left, bottom.  If no two corners have the same color, the background color\nis the color of the upper left corner.\n\nIn a typical photograph, the area that you would consider the background is many shades of  a\ncolor,  so  to  pambackground  it  is multiple colors and pambackground will not meaningfully\nidentify the background of your image.  To use pambackground in this case, you might use ppm‐\nchange to change all similar colors to a single one first.  For example, if the photograph is\na building against a blue sky, where nothing remotely sky-blue appears in the  building,  you\ncould  use  ppmchange  to change all pixels within 20% of \"SkyBlue\" to SkyBlue, then run pam‐\nbackground on it.\n\nYou might even extract the argument for ppmchange from the image in question,  using  pamget‐\ncolor.  In the foregoing example, we knew the background was approximately SkyBlue, but if we\ndidn't  we  could  just get the color of the top left pixel, in a form suitable for the color\narguments of ppmchange like this:\n\n$ color=$(pamgetcolor 0,0 -infile=/tmp/bodyskl|cut --fields=2 -delim=' ')\n\n\nA more convenient means of dealing with a multi-shade background is to use pnmquant  to  pro‐\nduce  a version of the image with a very small number of colors.  The background would likely\nthen be all one color.\n\nIf the pnmquant and ppmchange methods above do not adequately distinguish  foreground  colors\nfrom background colors, you can try a more elaborate method using pnmremap.  If you can manu‐\nally  create  a  palette  with  one color to which all the background pixels are similar, and\nother colors to which the foreground pixels are similar, you can use it as input to  pnmremap\nto  create  a smarter version of what you get with the pnmquant or ppmchange methods, so that\npambackground is more likely to separate background from foreground as your eye does.\n\nThe PAM that pambackground creates has a single plane, with a maxval of 1.  The sample  value\n1  means  background;  0 means foreground.  There is no tuple type.  Some older programs (but\nnone that are part of Netpbm) don't know what a PAM is and expect a mask to be in the form of\na PGM or PBM image.  To convert pambackground's output to PBM, use pamtopnm -assume.  To con‐\nvert to PGM, use pgmtopgm.\n\nnetpbmfile is the file specification of the input file, or - to indicate Standard Input.  The\ndefault is Standard Input.\n\nA common use for a background mask is with pamcomp.  You could replace the entire  background\n(or foreground) of your image with something else.\n\nAnother  common use is to make an image with the background transparent (in some image format\nthat has a concept of transparency) so that image can be overlaid onto another  image  later.\nNetpbm's  converters  to image formats that have transparency (e.g. PNG) let you use the mask\nthat pambackground generates to identify the transparent areas for the output.  You can  cre‐\nate a PAM image with transparency with pamstack.\n\nTo simply make a mask of all the areas of a specified color, use ppmcolormask.  If you have a\nunique  background color (one that doesn't occur in the foreground) and know what it is, this\ncan create a background mask in cases that pambackground cannot: where there are  see-through\nholes in the foreground image.\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\\ ), pambackground recognizes the following command line option:\n\n\n\n",
            "subsections": [
                {
                    "name": "-verbose",
                    "content": "Tell interesting facts about the process.\n\n\n\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "$ pambackground test.ppm | pnminvert >/tmp/bgmask.pgm\n$ pamcomp -alpha=bgmask.pgm test.ppm wallpaper.ppm >output.ppm\n\n$ pnmquant 5 test.pgm | pambackground test.ppm >/tmp/bgmask.pam\n\n\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ppmcolormask(1),  pamcomp(1),  ppmchange(1),  pnmquant(1),  pnmremap(1),  pamtopnm(1),   pgm‐\ntopgm(1), pamstack(1), pamgetcolor(1), pbmmaskd(1), pnm(1), pam(1),\n\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "pambackground was new in Netpbm 10.37 (December 2006).\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/pambackground.html\n\nnetpbm documentation                      24 November 2014              Pambackground User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pambackground - create a mask of the background area of an image",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Tell interesting facts about the process."
        }
    ],
    "examples": [
        "$ pambackground test.ppm | pnminvert >/tmp/bgmask.pgm",
        "$ pamcomp -alpha=bgmask.pgm test.ppm wallpaper.ppm >output.ppm",
        "$ pnmquant 5 test.pgm | pambackground test.ppm >/tmp/bgmask.pam"
    ],
    "see_also": [
        {
            "name": "ppmcolormask",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmcolormask/1/json"
        },
        {
            "name": "pamcomp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamcomp/1/json"
        },
        {
            "name": "ppmchange",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmchange/1/json"
        },
        {
            "name": "pnmquant",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnmquant/1/json"
        },
        {
            "name": "pnmremap",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnmremap/1/json"
        },
        {
            "name": "pamtopnm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamtopnm/1/json"
        },
        {
            "name": "topgm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/topgm/1/json"
        },
        {
            "name": "pamstack",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamstack/1/json"
        },
        {
            "name": "pamgetcolor",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pamgetcolor/1/json"
        },
        {
            "name": "pbmmaskd",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pbmmaskd/1/json"
        },
        {
            "name": "pnm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnm/1/json"
        },
        {
            "name": "pam",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pam/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Create a mask of the background in a PAM image.",
        "examples": [
            {
                "description": "Create a mask of the background in a PAM image",
                "command": "pambackground {{path/to/image.pam}} > {{path/to/output.pam}}"
            }
        ]
    }
}