PicaJet

Reference Formats

PGM

A Netpbm raster format storing 8-bit (or 16-bit, since a 2000 extension) grayscale intensity values per pixel in plain-text or raw binary form, used as a simple portable intermediate image format.

Extension

.pgm

Full name

Portable Graymap

Introduced

1988, added to Pbmplus alongside PPM

Vendor

Jef Poskanzer / the Netpbm project

What is inside the container

A PGM file carries a short header (magic number, dimensions, maximum gray value) followed by uncompressed grayscale samples; the April 2000 extension to the Netpbm formats allowed 2 bytes per sample for a maximum value of 65535. Like its siblings, PGM has no provision for EXIF, IPTC, XMP, or ICC metadata, and no layers, transparency, or color.

How to open it

Cross-platform editor GIMP opens and exports PGM
Command line Netpbm tools and ImageMagick convert read/write PGM
Scientific computing OpenCV, MATLAB, and scikit-image commonly read/write PGM for grayscale test data
Viewers IrfanView and XnView open PGM for inspection

For archives

PGM is well suited to scientific-imaging and computer-vision working pipelines but not to DAM archival — it cannot embed provenance, rights, or descriptive metadata. Convert any PGM asset destined for long-term cataloging to TIFF or PNG so a DAM can attach and preserve the metadata it needs.

PGM followed PBM by the end of 1988, added by Jef Poskanzer to Pbmplus once it became clear that a bitonal format alone couldn’t serve grayscale imaging needs. It kept the same design philosophy — a trivially simple header plus raw samples, readable and writable by almost any tool with minimal effort — but added the tonal range needed for photographs and scientific data converted to gray levels.

In practice, PGM today survives mainly as an interchange format inside computer-vision and scientific-imaging toolchains (test datasets, sensor dumps, algorithm output) rather than as a photographic deliverable. For a DAM, that means PGM files usually arrive as intermediate artifacts from an image-processing pipeline, not as assets with their own rights or captioning needs. The practical rule is the same as for PBM and PPM: PGM is fine as a working format between tools, but a DAM should normalize it to TIFF or PNG before treating it as a catalogued, metadata-bearing asset.

Frequently asked

Can PGM carry EXIF, IPTC, or XMP metadata?

No. The Netpbm header defines only a magic number, width, height, and maximum gray value — there is no field for EXIF, IPTC, XMP, or an embedded ICC profile. The only free-form data allowed is a '#' comment line, which most tools ignore. For a DAM, this means capture metadata, keywords, and rights information must be tracked in an external database or attached only after converting the file to TIFF, PNG, or JPEG, which natively support metadata blocks.

What bit depths does PGM support for grayscale data?

8-bit by default, with a 2000 extension to the Netpbm formats allowing 2 bytes per sample for a maximum value of 65535, which matters when a DAM needs to preserve tonal precision from scientific-imaging sources.

Is PGM suitable as a DAM archival master?

No. PGM is well suited to scientific-imaging and computer-vision working pipelines but not to archival, since it cannot embed provenance, rights, or descriptive metadata; convert to TIFF or PNG for long-term cataloging.

What does a PGM file structurally contain?

A PGM file opens with an ASCII header: a two-character magic number ('P2' for plain ASCII data or 'P5' for raw binary), followed by whitespace-separated width, height, and maximum gray value (maxval, up to 65535). An optional '#' comment line may appear before these fields. After the header comes the raster itself — width×height gray samples, one byte per pixel if maxval is under 256, otherwise two bytes, with no compression, palette, or channel structure beyond a single grayscale plane.

Which software commonly reads and writes PGM in practice?

The Netpbm package itself (its pnm/pgm command-line converters) is the reference implementation, and most general image editors interoperate with it: GIMP and ImageMagick both open and export PGM directly. In scientific and computer-vision contexts, OpenCV, MATLAB, and Python libraries such as scikit-image and Pillow read and write the format natively, since its plain header and uncompressed samples make it a simple, dependency-free way to dump raw grayscale arrays to disk.

Does PGM support color images?

No. PGM is grayscale-only by design — each pixel stores a single intensity sample, with no red/green/blue channels and no palette. It belongs to the Netpbm family alongside PBM (1-bit black-and-white) and PPM (full RGB color); a file containing color data must be saved as PPM instead, or as the more general PAM format, which supports arbitrary channel counts including alpha. Software that outputs 'PGM' from a color source has silently discarded the chroma information.

Why might a DAM encounter PGM files at all?

PGM commonly appears as an output or intermediate format from scientific-imaging and computer-vision pipelines, where its simple, uncompressed, tool-agnostic structure makes it easy for research software to write and read.

Is PGM compressed?

No. Both PGM variants store samples uncompressed — the binary (P5) form writes one or two raw bytes per pixel with no run-length or entropy coding, and the ASCII (P2) form is larger still, since each gray value becomes several bytes of decimal text plus whitespace. This makes PGM fast to parse but poorly suited to long-term storage: a DAM ingesting PGM files should convert them to PNG or TIFF for the archival master and keep PGM only as a transient working format.

Sources