Reading .pgm Files in LabVIEW

Updated May 30, 2018

Reported In


  • LabVIEW


  • NI-IMAQdx

Issue Details

I have an image file saved by a third-party camera utility software with the extension of .pgm. I tried using the IMAQ to open this file. I’m returned with an error “IMAQ Vision: (Hex 0xBFF604AB) Unable to read data”. How do I read the file information in LabVIEW to be displayed in an IMAQ image indicator?


To read a PGM file in LabVIEW, you need to use the Read Binary
The header format is as described below:

<width> <height>
<maximum grey value>

For an 8-bit image of size 320x240 the header would look like the following:

320 240

This header is followed by an array of pixel values corresponding to the image. If the maximum gray value is less than 256 then each pixel is represented by 1-byte. Otherwise, it uses 2-bytes.
Attached below is an image on how to use the Read from Binary to read the image information as a 2D array of integer values.  Alternatively, this 2D array of integers could be converted to an image data-type using the IMAQ

Additional Information

 A PGM (Portable Grey Map) image represents a grayscale graphic image. Simply put, it could be considered as an array of arbitrary integers preceded by a header.