{
    "mode": "man",
    "parameter": "pbmmask",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pbmmask/1/json",
    "generated": "2026-09-01T08:29:02Z",
    "synopsis": "pbmmask [-expand] [pbmfile]",
    "sections": {
        "NAME": {
            "content": "pbmmask - create a mask bitmap from a regular bitmap\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "pbmmask [-expand] [pbmfile]\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\npbmmask reads a PBM image as input and generates a corresponding mask of the foreground areas\nas another PBM image.\n\nThis is probably obsoleted by pambackground.\n\n\nThe color to be interpreted as \"background\" is determined automatically.  Regardless of which\ncolor  is background, the mask will be white where the background is and black where the fig‐\nure is.\n\nThis lets you do a masked paste like this, for objects with a black background:\n\npbmmask obj > objmask\npnmpaste < dest -and objmask <x> <y> | pnmpaste -or obj <x> <y>\n\n\nFor objects with a white background, you can either invert them or add a step:\npbmmask obj > objmask\npnminvert objmask | pnmpaste -and obj 0 0 > blackback\npnmpaste < dest -and objmask <x> <y> | pnmpaste -or blackback <x> <y>\n\n\nNote that this three-step version works for objects with black backgrounds too, if you  don't\ncare about the wasted time.\n\nYou  can  also  use  masks with grayscale and color images, using the pnmarith tool.  For in‐\nstance:\n\nppmtopgm obj.ppm | pamditherbw -threshold | pbmmask > objmask.pbm\npnmarith -multiply dest.ppm objmask.pbm > t1.ppm\npnminvert objmask.pbm | pnmarith -multiply obj.ppm - > t2.ppm\npnmarith -add t1.ppm t2.ppm\n\n\nAn interesting variation on this is to pipe the mask through pnmsmooth before using it.  This\nmakes the boundary between the two images less sharp.\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\\ ), pbmmask recognizes the following command line option:\n\n\n",
            "subsections": [
                {
                    "name": "-expand",
                    "content": "Expands the mask by one pixel out from the image.  This is useful if you want a little\nwhite  border around your image.  (A better solution might be to turn the pbmlife pro‐\ngram into a general cellular automaton tool...)\n\n\n\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "pambackground(1)  ppmcolormask(1),  pnmpaste(1),  pnminvert(1),   pnmarith(1),   pnmsmooth(1)\npbm(1),\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright (C) 1988 by Jef Poskanzer.\n\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "pbmmask is one of the oldest programs in Netpbm.  In September 2021,\nthe date on this manual was August 8, 1989 (being the date of the last\nsubstantial update).  We updated the page  then just to add this historical\ninformation and recommend pambackground.\n\nIt is likely that when Bryan wrote pambackground in 2006, he was\nunaware pbmmask existed.  Otherwise, he would presumably have\nreplaced pbmmask with a wrapper around pambackground.\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/pbmmask.html\n\nnetpbm documentation                      28 September 2021                   Pbmmask User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pbmmask - create a mask bitmap from a regular bitmap",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Expands the mask by one pixel out from the image. This is useful if you want a little white border around your image. (A better solution might be to turn the pbmlife pro‐ gram into a general cellular automaton tool...)"
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "pbm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pbm/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Create a mask bitmap from a regular bitmap.",
        "examples": [
            {
                "description": "Create a mask bitmap separating background from foreground",
                "command": "pbmmask {{path/to/image.pbm}} > {{path/to/output.pbm}}"
            },
            {
                "description": "Expand the generated mask by one pixel",
                "command": "pbmmask {{-r|-expand}} {{path/to/image.pbm}} > {{path/to/output.pbm}}"
            }
        ]
    }
}