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 2-D array for grayscale images or a (3, n, m) array for TrueColor images. Byte arrays are returned for 8-bit PPM files (MAXVAL < 256), while uint arrays are returned for 16-bit PPM files.
Files to be read should adhere to the PGM/PPM standard. The following file types are supported: P2 (graymap ASCII), P5 (graymap RAWBITS), P3 (TrueColor ASCII pixmaps), and P6 (TrueColor RAWBITS pixmaps). 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 read_ppm.pro in the lib subdirectory of the IDL distribution.
Note: To find information about a potential PPM file before trying to read its data, use the QUERY_PPM function.
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
READ_PPM, Filename, Image [, MAXVAL=variable]
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 2-D byte or uint array. For TrueColor images, Image is a (3, n, m) byte or uint array.
A named variable that will contain the maximum pixel value.
Added support for 16-bit files
IOPEN, WRITE_PPM, QUERY_PPM