The PGM Image File Format

C. Furlong
WPI-ME/CHSLT

Description

PGM is a standard bitmap based format consisting of a 4 lines header, and data stored in the unsigned char type, providing a maximum of 256 gray scale levels or 8-bit data per pixel.

The general structure of a PGM image file

The header of a PGM image file consists of: Data follows the header information and is written in pixel values (in text or binary format).  Data is in raster order, which indicates that all data for the first row of the image is written first, then for the second row, and so on.  The origin of the coordinate system for a PGM image is located on the top left corner.

The following is a 10 x 10 pixels PGM text (ASCII) image file containing a maximum gray scale value of 255:
 

P5
#WPI-ME/CHSLT generated image Ver.1.0 (0)
10 10
255
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 28 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
255 255 255 255 255 255
Header is written in ASCII (or text) format and data in ASCII or binary format

PGM file images are generally used for displaying/printing purposes and can be read by many commercially available image packages, including a public domain UNIX based named xv.


Back to top
Back to ME-593N page


[Main]



[Mechanical Engineering Department]


[CHSLT / NEST Labs]