pgmtopbm
Convert PGM image to PBM image
TLDR
View documentation for the current command
SYNOPSIS
pgmtopbm [ -threshold value | -value value ] [ pgmfile ]
PARAMETERS
-threshold value
Specifies the grayscale value that serves as the threshold for conversion. Pixels with grayscale values less than this value become black, and others become white. The value must be between 0 and the maximum grayscale value of the input PGM.
-value value
An alias for the -threshold option. It functions identically, allowing you to specify the threshold grayscale value for conversion.
pgmfile
The path to the input PGM image file. If omitted, pgmtopbm reads the PGM image data from standard input.
DESCRIPTION
pgmtopbm is a utility from the Netpbm package that converts a Portable GreyMap (PGM) image file into a Portable BitMap (PBM) image file. A PGM image represents various shades of gray, while a PBM image is purely black and white (binary). The conversion is performed by applying a threshold: any pixel with a grayscale value less than the specified threshold becomes black, and any pixel with a value greater than or equal to the threshold becomes white.
By default, if no threshold is provided, pgmtopbm uses the mid-point of the maximum grayscale value of the input PGM as the threshold. The command reads the PGM image from standard input if no filename is specified, and writes the resulting PBM image to standard output.
CAVEATS
The conversion from PGM to PBM is inherently lossy, as it reduces a wide range of grayscale values to just two (black or white). This process discards significant image information, and the quality of the output PBM heavily depends on the chosen threshold. Careful selection of the threshold is crucial for desired results.
DEFAULT THRESHOLD BEHAVIOR
If neither -threshold nor -value is specified, pgmtopbm automatically calculates a default threshold. This default is half the maximum grayscale value of the input PGM image. For example, if the PGM has a maximum value of 255, the default threshold will be 127 or 128 (depending on rounding).
STANDARD INPUT/OUTPUT
pgmtopbm is designed to work seamlessly with pipes. If no pgmfile is given, it reads from standard input. The resulting PBM image is always written to standard output. This allows for easy chaining with other Netpbm commands, e.g., 'cat image.pgm | pgmtopbm -threshold 100 | pbmtofig > output.fig'.
HISTORY
pgmtopbm is an integral part of the Netpbm suite of graphics tools, which originated from Jef Poskanzer's pbmplus package. This project standardized the Portable BitMap (PBM), Portable GreyMap (PGM), and Portable PixMap (PPM) formats, providing a foundational set of command-line utilities for manipulating these images. pgmtopbm serves as a basic yet essential conversion tool, enabling transformations between grayscale and binary image data formats within the Netpbm ecosystem.