Chip in

PGM file format (.pgm)

Netpbm greyscale bitmap.

Last updated

What is a PGM file?

In short: A PGM file (.pgm) is an image file in the PGM format. PGM stores a single brightness value per pixel and nothing else. It can be converted to JPG, PNG or WEBP for free in a web browser with iHateFiles, without uploading it.

The greyscale member of the Netpbm family, from the same late-1980s Unix toolkit.

PGM stores a single brightness value per pixel and nothing else. It is used wherever colour is irrelevant or would get in the way: depth maps, height fields, masks, medical and scientific imaging, and computer vision test data.

What PGM is good at

  • Trivially simple to read and write
  • Lossless, with 8 or 16 bits per pixel
  • A third the size of the colour equivalent

Where PGM falls short

  • No colour, and converting to it discards colour permanently
  • No compression
  • Not viewable in a browser

When to use PGM

Use PGM for masks, depth data and computer vision work where a single channel is what you want.

How to open a PGM file

Scientific and image processing tools.

Opening a .pgm file on each platform
WindowsIrfanView or GIMP.
macOSGIMP or ImageMagick; Preview will not.
LinuxGIMP, ImageMagick and the netpbm tools.
PhoneNeeds a dedicated viewer.
In a browserNo browser displays PGM.

The thing that usually goes wrong

Converting a colour image to PGM throws the colour away for good. Keep the original if you might want it back.

Inside a PGM file

PGM is the greyscale member of the Netpbm family: identical to PPM in every respect except that each pixel is one value rather than three. The header is P5 and then the same plain-text width, height and maximum value.

Its real home is computer vision and medical imaging, where images are frequently single-channel to begin with and where a format that adds nothing between the algorithm and the data is a feature. OpenCV, ImageJ and most academic imaging tools read and write it without a thought.

PGM at a glance
Full namePortable Graymap
Magic bytesP5 for binary, P2 for ASCII
ChannelsOne — greyscale only
Bit depth8 or 16 bits per pixel
CompressionNone
Common inComputer vision, medical and scientific imaging

Questions

What is a PGM file?

Netpbm greyscale bitmap. Files use the .pgm extension.

How do I open a PGM file?

Most image software opens PGM directly. If yours does not, convert it here to something more common. It takes a few seconds and nothing is uploaded.

Can I convert PGM for free?

Yes. Every conversion here is free and unlimited, because your own device does the work rather than a server we have to pay for.

Is PGM lossless?

Partly. The compression itself loses nothing, but PGM first reduces the image to greyscale, discarding all colour, and that step cannot be undone. Flat graphics survive it well; photographs visibly do not.