Portable gray map

The portable gray map or PGM is a very simple raster image file format, perhaps the simplest possible. It is useful for low-level image manipulation and conversion, and for handling images with easy-to-use tools like awk and Python. PGM files can be opened in GIMP.

Format specification
A PGM file is a text file consisting of gray level values in ASCII decimal. The so-called plain format is as follows:


 * A line with the format's magic number P2, in ASCII text
 * A comment line starting with a hash character, such as # filename.pgm
 * A line with the image dimensions in columns then rows, eg 800 600 for an image 800 pixels wide
 * A line with the maximum gray level value, greater than 0 but equal to or less than 65535
 * The pixel gray values, separated by white space, with black = 0

Simple example
From Wikipedia's article about the Netpbm format, a generic superset of the PGM.

Example, actual size:



...and and magnified 10&times;:



Geoscience example
To convert a seismic timeslice to an image, make a horizon amplitude extraction on a constant time, export the horizon, extract the Z-field (e.g. with awk), change the distribution to be zero-centered (for example, for a 16-bit image, ), then add the header in a text editor.

Here are the first few lines of a PGM; the first four lines are the header: