Define Execution Order with IMAQ images in LabVIEW

Updated Jan 6, 2023

Reported In

Driver

  • NI-IMAQ

Issue Details

My images are different each time run my application, how can I make sure it's processed in the right order?

How can I avoid race conditions when working with images or IMAQ

Solution

Image data types are stored differently to normal datatypes (eg. integers/strings/booleans), this means race conditions can be caused in situations where normal datatypes would not cause them.

To ensure this doesn't happen, functions accessing the image need a defined execution order. 

For example the following block diagram shows two functions where the order of execution is not defined. Either Image display (A) or IMAQ Threshold (B) will execute first but we don't know which. IMAQ Mophology (C) will still always execute last. 


One method to ensure the image is displayed (A) before processing begins (B) is to place the function you want to happen first in a sequence structure. There are other ways to establish execution order, this is just an example. This shown in the figure below.






 

Additional Information

IMAQ images require the creation of an image buffer in PC memory.  Each buffer has a unique name, and these buffers are accessed in LabVIEW by pointers.  Thus, the image data type in LabVIEW is actually a reference to a particular memory location where the image is stored.

The reason for this is that images typically take up a significant amount of memory (as compared with more primitive data types).  Having a preallocated memory space which gets reused eliminates the need to continually keep reallocating memory for the same image every time a processing step is performed on the image.

Since an image wire in LabVIEW refers to a particular place in memory, and the data stored in this location will be frequently changed, it is important to control when various steps will access the image buffer.  Because images break the typical dataflow paradigm, you can encounter race conditions when working with images that you would not encounter when working with other data types.