LinuxCommandLibrary

pbmtopgm

Convert PBM image to PGM image

TLDR

Convert PBM image to PGM by averaging the wxh-sized area surrounding each pixel

$ pbmtopgm [w] [h] [path/to/image.pbm] > [path/to/output.pgm]
copy

SYNOPSIS

pbmtopgm [pbmfile]

DESCRIPTION

The pbmtopgm command is a utility within the Netpbm package designed to convert images from the Portable BitMap (PBM) format to the Portable GreyMap (PGM) format.

A PBM file represents a monochrome (black and white) image, where each pixel is either black or white. A PGM file represents a grayscale image, where each pixel has a single intensity value, typically ranging from 0 (black) to 255 (white).

When pbmtopgm performs the conversion, it maps the black pixels from the input PBM image to a pixel value of 0 (pure black) in the output PGM image. Conversely, it maps the white pixels from the PBM image to a pixel value of 255 (pure white) in the PGM image. The output PGM image will always have a maximum grayscale value (maxval) of 255. This command is fundamental for transforming 1-bit monochrome images into 8-bit grayscale images, enabling further grayscale-specific manipulations.

CAVEATS

The command expects valid PBM input. If the input is not a correctly formatted PBM image, it may produce an error or unexpected output.
The output PGM image will always have a maxval of 255, performing a direct 1-bit (black/white) to 8-bit (0/255) mapping without intermediate grayscale levels.

STANDARD INPUT/OUTPUT

If pbmfile is not specified, pbmtopgm reads the PBM image data from standard input. It always writes the resulting PGM image to standard output. This behavior makes it ideal for use in command-line pipelines, where the output of one Netpbm command can be directly fed as input to another.

HISTORY

pbmtopgm is part of the extensive Netpbm package, a collection of graphics manipulation programs and libraries that originated in the late 1980s. The Netpbm project, initially developed by Jef Poskanzer, aims to provide a set of atomic tools for basic image processing, often used in pipelines. This command reflects the Unix philosophy of small, specialized tools that do one thing well, and its design has remained consistent over decades.

SEE ALSO

pgmtopbm(1), pbm(5), pgm(5), netpbm(1)

Copied to clipboard