Example Code

IMAQ Threshold Binary Image and Mask

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.


  • Vision Development Module
  • LabVIEW

Code and Documents



The example demonstrates how to apply a binary threshold to an image.



For some VISION algorithms, a binary image is necessary to perform the calculation. Threshold your grayscale or color image to create a binary image. Creating a binary image separates the objects that you want to inspect from the background. The threshold operation sets the background pixels to 0 in the binary image, while setting the object pixels to a non-zero value. Object pixels have a value of 1 by default, but you can set the object pixels to have any value you choose.

After creating a binary image of the original image, a masked image is created by applying the binary image as an image mask to the original image. The masked image contains the grayscale representation of the original image, but the parts of the binary image that are considered background pixels are blacked out in the masked image.




  • LabVIEW 2012 Base Development System (or compatible)
  • Vision Development Module 2012 (or compatible)


  • No hardware is necessary to use this example VI


Steps to Implement or Execute Code

  1. Run the VI
  2. Adjust the 'Lower Value' and 'Upper Value' sliders


Additional Information or References

IMAQ Threshold Mask LV2012 NIVerified.vi - Front Panel.png


IMAQ Threshold Mask LV2012 NIVerified.vi - Block Diagram.png


Create a Binary Image - NI Vision 2011 for LabVIEW Help

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text 'NIVerified'. Read here for more information about the new Example Guidelines and Community Platform.**

Isaac S.
Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.