This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Reading .pgm Files in LabVIEW

Updated May 30, 2018

Reported In

Software

  • LabVIEW

Driver

  • NI-IMAQ
  • 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 ReadFile.vi 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?

Solution

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

P5
 
<width> <height>
<maximum grey value>
 

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

P5
 
320 240
255

 
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 File.vi 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 ArrayToImage.vi.

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.