Using Image Variables in Vision Builder AI

Updated Nov 19, 2020

Environment

Software

  • Vision Builder for Automated Inspection

Vision Builder for Automated Inspection 2010 (Vision Builder AI) introduces image variables, which can be used in many different ways. The following sections describe how to create image variables, considerations for using image variables, and how to use image variables in specific use cases. Some use case demonstrations require additional files, which are attached at the end of the document.

Working with Variables in Vision Builder AI

Vision Builder AI includes a Variable Manager, which you can use to easily create or edit variables. The Variable Manager interface includes the following tabs:

  • Inspection Variables—Lists variables that only the current inspection can access.

  • System Variables— Lists variables that all inspections can access.
     

Note  If you enable the Network Shared checkbox for a variable, the variable is available to other devices on the same network.
 

  • Network Variables—Lists variables shared by another device on the same network that all inspections can access.
     

Note  External applications can update shared system or network variables. Steps that read a shared system or network variable always get the current value of the variable.
 

Creating Image Variables

Complete the following steps to create an image variable in Vision Builder AI:
 

  1. In the Vision Builder AI Configuration Interface, select Tools»Variable Manager.
     


 

  1. Select the Inspection Variable, System Variable, or Network Variable tab. Refer to Working with Variables in Vision Builder AI for more information about each tab.

  2. Select Add to open the Add Variable dialog box.

  3. Select Image in the Type list.

  4. Configure the remaining variable settings and click OK.
     

Note  Unlike other variable types, image variables do not have initial values.
 

  1. Verify that the new variable appears in the list of variables and click OK to close the Variable Manager.
     

The image variable is created and available to steps that interact with image variables.
 

Using Image Variables

Use the following Vision Builder AI steps to interact with image variables:
 

  • Select Image—Selects an image variable for subsequent steps to process.

  • Set Variable—Sets the value of an image variable.

  • Vision Assistant—Creates a Vision Assistant sequence, which can retrieve, operate on, and set image variables.

  • Run LabVIEW VI—Can use image variables as VI inputs. The Run LabVIEW VI outputs the same image that is passed to the step.

  • Image Logging—Saves image variable content to the specified location.

  • Update Inspection UI—Updates image display controls in a custom inspection interface with image variable content.
     

Considerations for Working with Image Variables

There are important differences between image variables that are network shared and image variables that are not network shared. Network shared image variables include Network Variables and System Variables with the Network Shared checkbox enabled.
 

Shared image variables require Vision Builder AI to access a variable library on disk. Image variables that are not shared are stored in memory. Accessing a variable library requires more time than accessing a variable in memory.
 

To improve performance, shared image variables are not updated when processing steps modify the image. Instead a local copy is updated in memory. If you want to update the shared image variable with the modified image, you must use a Set Variable step to update a shared image variable in the variable library with the current image.
 

You cannot directly update shared image variables in a Run LabVIEW VI step because the step operates on the local copy of the variable in memory. To update a shared image variable using a Run LabVIEW step, you must update an inspection image variable in the Run LabVIEW step and then use a Set Variable step to update the network shared image variable with the value from the inspection image variable.
 

Use Cases

The following sections describe specific applications that use image variables.
 

Acquiring Images with a Run LabVIEW VI Step

This use case uses a dynamic file path to read a file from disk. For example, imagine that a PLC controls another part of the inspection system and communicates a file path when an image is available for processing.
 

Complete the following steps to configure an inspection in Vision Builder AI to handle this use case:
 

  1. Download and decompress the attached Examples.zip file at the end of this document and copy the User Images folder to your C:\ drive. 

  2. On the Vision Builder AI Welcome screen, select New Inspection to launch the Vision Builder AI Configuration Interface.

  3. Create an image Inspection variable.

 

  1. Select Tools»Variable Manager.

  2. In the Inspection Variables tab, add a new image variable with the name Local Image. Refer to Creating Image Variables for more information about how to add a new image variable.
     

 
 

  1. Verify that the new variable appears in the list of variables and close the Variable Manager.

 

  1. Select the  Use Additional Tools palette.
  2. Click the  Run LabVIEW VI step.
  3. Complete the following steps to configure the Run LabVIEW VI step:

 

  1. In the VI Path control, select  Browse.

  2. Navigate to the Read Image VI and click OK.

  3. Select the VI Controls tab and click Configure to open the Select VI Value dialog box.

  4. In the VI Controls list, select Image.

  5. Enable the Use Measurement option and select Inspection Variable - Local Image from the list.
     

  

  1. In the VI Controls list, select Path. In the described use case, the path value requires a previous measurement generated by a PLC. For this example, select Use Constant and specify the filepath of an image on your computer. Click OK to close the Select VI Value dialog box.

 

  1. Click OK to add the step to the inspection.
     

The Read Image VI reads the file at the specified path and updates the image variable with the read image.  No image appears in the main window because the Run LabVIEW step always passes out the image that is passed into it.
 

Complete the following steps to access and display the updated image variable:
 

  1. 1. Select the  Acquire Images palette.

  2. 2. Click the  Image Select step.

  3. 3. In the Image Selection tree, select Local Image. The main window displays the content of the Local Image variable.

  4. 4. Click OK to add the step to the inspection.
     

The inspection is configured to select the image variable. You can add additional steps to process the selected image.
 

Measuring Part Movement between Inspection Iterations

This use case illustrates how to use an image variable to process an image from a previous iteration of the inspection. This use case also illustrates how to store an intermediate image result using a temporary image variable.
 

Complete the steps in the following sections to configure an inspection in Vision Builder AI to handle this use case.
 

Creating Inspection Variables

  1. Download and decompress the attached Examples.zip file at the end of this document and copy the User VIs folder to your C:\ drive.

  2. On the Vision Builder AI Welcome screen, select New Inspection to launch the Vision Builder AI Configuration Interface.

  3. Create an image Inspection variable.

 

  1. Select Tools»Variable Manager.

  2. In the Inspection Variables tab, add two new image variables with the names Previous Image and Temp Image. Refer to Creating Image Variables for more information about how to add a new image variable.

  3. Add a point variable with the name Previous Point.
     


 

  1. Verify that the new variables appear in the list of variables and close the Variable Manager.
     

Configuring the Setup State

Use the Setup state to initialize the inspection variables with valid values the first time the inspection runs.
 

  1. 1. Select View»View Complete Inspection Setup to display the Setup and Cleanup states of the inspection.

  2. 2. Click Setup.

  3. 3. Select the  Acquire Images palette.

  4. 4. Click the  Simulate Acquisition step. Complete the following steps to configure the step:

 

  1. a. In the Path control specify the path to Object14.jpg in the sample images folder that you downloaded in step 1.

  2. b. Disable the Cycle Through Folder Images checkbox.

  3. c. Click OK to add the step to the inspection.
     

 

  1. Select the  Locate Features palette.

  2. Click the  Detect Objects step. Complete the following steps to configure the step:

 
  1. a. Select Full Image in the Region of Interest list.

  2. b. Select the Threshold tab.

  3. c. Select Dark Objects in the Look For list.

  4. d. Select Local Threshold: BG Correction in the Method list.

  5. e. Click OK to add the step to the inspection.

 

  1. Select the  Use Additional Tools palette.

  2. Click the  Set Variable step. Complete the following steps to configure the step:

 

  1. Select the Previous Image variable.

  2. Enable the Set to Measurement option and select Current Image.

  3. Select the Previous Point.X variable.

  4. Enable the Set to Measurement option and select theX position measurement returned by the Detect Objects step

  5. Select the Previous Point.Y variable.

  6. Enable the Set to Measurement option and select theY position measurement returned by the Detect Objects step.

  7. Click OK to add the step to the inspection.
     

Configuring the State Diagram

Configure the inspection state diagram to perform an inspection that measures the movement of parts between one inspection iteration and the next.
 

  1. Click  Toggle Main Window View.

  2. Click State Diagram. Use the Setup state to initialize the inspection variables with valid values the first time the inspection runs.

  3. Select the  Acquire Images palette.

  4. Click the  Simulate Acquisition step. Complete the following steps to configure the step:

 

  1. In the Path control specify the path to Object01.jpg in the sample images folder that you downloaded in step 1.

  2. Click OK to add the step to the inspection.
     

 

  1. Select the  Locate Features palette.

  2. Click the  Detect Objects step. Complete the following steps to configure the step:

 

  1. Select Full Image in the Region of Interest list.

  2. Select the Threshold tab.

  3. Select Dark Objects in the Look For list.

  4. Select Local Threshold: BG Correction in the Method list.

  5. Click OK to add the step to the inspection.
     

The inspection is configured to detect objects in the inspection image.
 

Complete the following steps to store the current image to a temporary image variable and retrieve the image from the previous inspection iteration.
 

  1. Select the  Enhance Images palette.

  2. Click the  Vision Assistant step.

  3. Select Full Image in the Region of Interest list.

  4. Click Edit to open Vision Assistant.

  5. In Vision Assistant, select the   Image palette.

  6. Click the  Image Buffer step.

  7. Enable the Store option.

  8. Select Inspection Variable – Temp Image in the Image Variables list.

  9. Click OK to add the step to the algorithm.

  10. Click a second  Image Buffer step.

  11. Enable the Retrieve option.

  12. Select Inspection Variable – Previous Image in the Image Variables list.

  13. Click OK to add the step to the algorithm.
     

By copying the current image to the Temp Image variable, we can process the image without modifying the original acquired image. In subsequent steps you will configure the inspection to copy the original acquired image to the Previous Image variable so that it is available in the next inspection iteration.
 

Complete the following steps to complete the Vision Assistant algorithm:
 

  1. Select the  Grayscale palette.

  2. Click the  Threshold step.

  3. Select Threshold: Background Correction in the Threshold Type list.

  4. Select Dark Objects in the Look For list.

  5. Click OK to add the step to the algorithm.

  6. Select the  Operators step.

  7. Select Multiply.

  8. Enable the Image option and select the Temp Image variable.

  9. Click OK to add the step to the algorithm.

  10. Click a second  Operators step.

  11. Select Add.

  12. Enable the Image option and select the Simulate Acquisition step for the Inspect state.

  13. Click OK to add the step to the algorithm.

  14. Close Vision Assistant.

  15. Click OK to add the step to the inspection.
     

The Vision Assistant step passes out an image that displays the position of the object in the previous inspection iteration, as well as the position of the object in the current inspection iteration. The object in the image from the previous iteration appears as a light object, and the current object appears as a dark object.
 

Complete the following steps to copy the original acquired image for the current inspection iteration available to a variable:
 

  1. Select the  Use Additional Tools palette.

  2. Click the  Set Variable step. Complete the following steps to configure the step:

 

  1. Select the Previous Image variable.

  2. Enable the Set to Measurement option and select the Simulate Acquisition step.

  3. Note: Do not select the Simulate Acquisition step in the Inspection Setup state.

  4. Select the Previous Point.X variable.

  5. Enable the Set to Measurement option and select theX position measurement returned by the Detect Objects step

  6. Select the Previous Point.Y variable.

  7. Enable the Set to Measurement option and select theY position measurement returned by the Detect Objects step.

  8. Click OK to add the step to the inspection.
     

The sample images archive includes an example inspection that illustrates how to create an overlay that indicates the motion of the object between one inspection iteration and the next.
 

Reading a Vision Builder AI Image from another System

This use case demonstrates how to add and interact with a Vision Builder AI target in a LabVIEW project.  Adding a target in Vision Builder AI mode allows other VIs in the LabVIEW project to access the variables shared by the target. You can drag shared variables from a remote target to a VI and display the images processed by Vision Builder AI as it runs on the remote target.

Use Case Requirements

The procedure for this use case requires the following:
 

  1. A development computer with LabVIEW 2010 or higher and Vision Builder AI 2010 or higher installed.

  2. One of the following NI Vision real time targets running Vision Builder AI 2010 or higher.
     

    • NI 17xx Smart Camera

    • NI CVS-1450 Series Compact Vision System

    • NI EVS-1463RT Embedded Vision System

    • NI EVS-1464RT Embedded Vision System
       

Adding a Remote Target to a LabVIEW Project in Vision Builder AI Mode

Complete the steps in the following sections add a target to a LabVIEW project in Vision Builder AI mode:
 

  1. Select Start»All Programs»National Instruments»LabVIEW to launch LabVIEW 2010 or higher.

  2. On the LabVIEW Welcome screen, select Empty Project.

  3. In the Project Explorer window, right-click Project: Untitled Project and select New»Targets and Devices.

  4. Select a remote target running Vision Builder AI 2010 or higher in the Targets and Devices list.

  5. Click OK.

  6. In the Target Mode Selection dialog box, select Vision Builder AI Mode and click Continue.
     


 

The remote target appears in the Project Explorer window.
 

Accessing Variables from a Remote Target in Vision Builder AI Mode

Complete the following steps to create and access a variable for a remote target in Vision Builder AI mode:
 

  1. In the Project Explorer window, right-click the remote target and select Connect. The status indicator in the target icon changes to green if Vision Builder AI is running on the target.



 

  1. Right-click the target and select Configure Vision Builder AI Inspection to launch Vision Builder AI.

  2. On the Vision Builder AI Welcome screen, click Browse under Configure Inspection and select the inspection that you want to run.

  3. Create an image System variable that is network shared.

 

  1. Select Tools»Variable Manager.

  2. Select the System Variables tab.

  3. In the System Variables tab, add a new image variable with the name My Image and the Publish on Network checkbox enabled. Refer to Creating Image Variables for more information about how to add a new image variable.
     


 

  1. Verify that the new variables appear in the list of variables and that the Network Shared checkbox is enabled, then close the Variable Manager.
     

 

  1. Click the last step in the inspection.

  2. Select the  Use Additional Tools palette.

  3. Click the  Set Variable step. Complete the following steps to configure the step:

 

  1. a. Select the My Image variable.

  2. b. Enable the Set to Measurement option and select Current Image.

  3. c. Click OK to add the step at the end of the inspection.

 
  1. Select Files»Save to save the inspection.

  2. Click  Run Inspection in Loop and verify that the inspection runs correctly.

  3. Stop the inspection and select File»Switch to Inspection Interface.

  4. Click  Run Inspection.

  5. Return to the LabVIEW Project Explorer window and note that the shared variable is listed beneath the remote target.
     

 
 

  1. Select My Computer.

  2. Right-click My Computer and select New» VI.

  3. Drag the My Image variable from the Project Explorer window to the VI block diagram.
     

Note: The new VI will run on the development computer.
 

  1. Build the following block diagram:
     


 

  1. Switch to the VI Front Panel and run the inspection.
     

The Image Display control displays the image acquired from the target running in Vision Builder AI mode.
 

A LabVIEW project can include multiple targets, including targets that are not running Vision Builder AI. The project illustrated in the following image includes different types of targets that use shared variables to expose results and images. Results from various types of hardware monitoring an entire assembly line can be combined in a single VI on the host computer, which can function as an HMI to the entire manufacturing floor.