Image Display Shows Incorrect Image in LabVIEW

Updated Apr 25, 2023

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • Vision Development Module

Driver

  • Vision Acquisition Software

Issue Details

I am using an image display in LabVIEW from the Vision and Motion palette. I have everything wired correctly, but the wrong image is being displayed. What can I do to correct this problem?

Solution

If you are not receiving any errors, but are seeing this behavior, the most likely cause is a race condition. The image data type in LabVIEW is slightly unconventional and thus, a brief discussion of the image data type will help us reach a solution to this problem. For a detailed discussion of the LabVIEW image data type, please refer to Image Datatypes in LabVIEW.

Because images typically contain large amounts of data, NI-IMAQ, the image acquisition driver and API, requires that you create a buffer in PC memory to pass images through LabVIEW. This is done by calling the IMAQ Create VI.
 
The Image Name input must be unique, and will be the name of this particular buffer. This buffer can be written and overwritten over and over again without allocating new memory. The New Image output is simply a reference to a physical location in memory where this image will be stored.

Many processing VIs have multiple image inputs. Typically, Image Src and Image Dst are the image inputs, and Image Dst Out is the output. This can be seen as an example bellow with the IMAQ Threshold VI.
 

If you wire the Image Src input, but not the Image Dst input, the Image Dst Out output will point to the same buffer as Image Src. If you do wire both inputs, then the Image Dst Out output will point to the Image Dst input.

Programmers should be aware of this, because if you have not initialized enough buffers to supply unique buffers for each input, you will end up overwriting a buffer that already exists. This is not a problem unless you are trying to preserve images at every step through the process.

Consider the following example:
 
In this example, there is one single buffer. Image Display 2 will definitely display image 2, but depending on the order of execution, Image Display 1 may display image 1 or image 2. If Image Display 1 is updated before IMAQ Threshold is called, then it will display image 1. If it is updated after IMAQ Threshold is called, it will display image 2. Now consider this second example.
 
In this example, there are two buffers: one for the original image, one for the thresholded image. Now, Image Display 1 will always display image 1, since its referring to the image buffer called Image1. Image Display 2 will always display image 2, since it is referring to the image buffer called Image Dest.

Many IMAQ and Vision VIs in LabVIEW take the general approach of having an Image Source and Image Destination inputs. The rule is this: whenever the destination input is unwired, the VI will replace the input image with the resulting image. Whenever the destination input is wired, the VI will place the resulting image into the destination buffer and preserve the input in the source buffer.

For each buffer created, an IMAQ Dispose VI is required to free the memory allocated to the IMAQ Create VI.
 

The IMAQ Dispose VI should be executed only when the image is no longer needed in you application. For example, if an image is being passed from a subVI to the main VI, executing IMAQ Dispose in the subVI will free the memory before the main VI reads the buffer. Therefore, the image is no longer available to be processed or displayed.

Additional Information

Images can also display incorrectly (i.e gray rectangle) when working with huge dimensions (i.e 35000x250000). This can be caused because of the possible limitations in the Windows libraries that our software (VAS or VDM) uses to display images. In this case, you may need to use the zooming tools available in the image display control or implement your own zooming functionality programmatically to visualize the image properly.