The READ_PPM procedure reads the contents of a PGM (gray scale) or PPM (portable pixmap for color) format image file and returns the image in the form of a 2D byte array (for grayscale images) or a (3, n , m ) byte array (for true-color images).

Files to be read should adhere to the PGM/PPM standard. The following file types are supported: P2 (graymap ASCII), P5 (graymap RAWBITS), P3 (true-color ASCII pixmaps), and P6 (true-color RAWBITS pixmaps). Maximum pixel values are limited to 255. Images are always stored with the top row first.

PPM/PGM format is supported by the PBMPLUS toolkit for converting various image formats to and from portable formats, and by the Netpbm package.

This routine is written in the IDL language. Its source code can be found in the file in the lib subdirectory of the IDL distribution.

Calling Sequence

READ_PPM, Filename , Image



A scalar string specifying the full path name of the PGM or PPM file to read.


A named variable that will contain the image. For grayscale images, Image is a 2D byte array. For true-color images, Image is a (3, n , m ) byte array.



A named variable that will contain the maximum pixel value.


To open and read the PGM image file named "foo.pgm" in the current directory and store the image in the variable IMAGE1:

READ_PPM, "foo.pgm", IMAGE1

See Also