Home

PGM

Portable GrayMap (PGM) is a grayscale image file format used to store per-pixel brightness. It is part of the Netpbm family, which also includes PBM (bitmap) and PPM (color). PGM emphasizes simplicity, portability, and ease of parsing, making it common in teaching, research, and basic image processing tasks.

A PGM file begins with a magic number: P2 for ASCII encoding or P5 for binary encoding.

PGM records a single intensity value per pixel, with no color channels or alpha. It is uncompressed

Software support is broad; many image libraries and tools can read and write PGM files. It is

Limitations include the lack of embedded metadata beyond width, height, and maxval, no color information, and

---

The
header
may
contain
comment
lines
starting
with
'#'.
After
the
header,
the
image
width,
height,
and
the
maximum
gray
value
(maxval)
are
listed.
Pixel
data
then
follow:
P2
stores
values
as
ASCII
decimal
numbers;
P5
stores
binary
samples.
If
maxval
exceeds
255,
binary
samples
use
two
bytes
per
sample;
otherwise
one
byte
per
sample.
and
lossless,
facilitating
straightforward
parsing
and
conversion.
Extensions
are
usually
.pgm,
though
alternate
names
may
appear.
often
used
for
grayscale
processing,
computer
vision
demonstrations,
and
as
a
simple
interchange
format
in
pipelines.
limited
efficiency
for
storage
compared
with
compressed
formats.
Nevertheless,
PGM
remains
a
standard
reference
format
within
the
Netpbm
family.