pbmmask
Create PBM mask from another image
TLDR
Create a mask bitmap separating background from foreground
Expand the generated mask by one pixel
SYNOPSIS
pbmmask [-background] value [pbmfile]
PARAMETERS
value
The character to match in the input PBM image. This is typically '0' (representing a white pixel) or '1' (representing a black pixel). Pixels in the input matching this character will be identified in the output mask.
-background
Inverts the mask output. If specified, pixels in the output mask that match the value character will be white, and non-matching pixels will be black. Without this option, matching pixels are black and non-matching are white.
pbmfile
The path to the input PBM image file. If omitted, pbmmask reads the PBM image from standard input (stdin).
DESCRIPTION
The pbmmask command is a utility within the Netpbm image processing suite. It takes a Portable Bitmap (PBM) image as input and generates another PBM image of identical dimensions. This output image functions as a mask, highlighting specific pixel values from the original.
Users specify a 'value' character, typically '0' for white or '1' for black, that pbmmask searches for in the input image. For every pixel in the input image that matches this 'value' character, the corresponding pixel in the output mask becomes black. All other pixels in the output mask are rendered white.
Optionally, the -background flag can be used to invert this behavior: matching pixels become white, and non-matching pixels become black. This command is particularly useful for isolating specific features, creating stencils, or preparing images for further processing where a binary mask is required.
CAVEATS
pbmmask operates exclusively on Portable Bitmap (PBM) images, which are binary (black and white) image formats. It does not support grayscale (PGM) or color (PPM) images directly. Ensure input images are correctly formatted PBM files for proper operation.
STANDARD INPUT/OUTPUT
Like most Netpbm tools, pbmmask adheres to the Unix philosophy of standard input and output. If no pbmfile is specified, it reads the input PBM image from standard input. The resulting masked PBM image is always written to standard output (stdout).
USAGE CONTEXT
This command is often used in pipelines with other Netpbm utilities for more complex image manipulations. For instance, one might use it to create a mask for a specific textual element rendered by pbmtext, or to extract a particular binary pattern from a scanned document.
HISTORY
pbmmask is part of the Netpbm project, a comprehensive suite of graphics file format converters and image processing utilities. Netpbm evolved from the PBMplus toolkit, which was initially developed by Jef Poskanzer in the late 1980s and early 1990s. The Netpbm suite, including pbmmask, has been a staple in Unix-like environments for manipulating pixelmap images, valued for its simplicity, efficiency, and extensibility through piping commands.