NI Vision
NI Vision
NI Vision
June 2011
372228M
Support
Worldwide Offices
Visit ni.com/niglobal to access the branch office Web sites, which provide up-to-date
contact information, support phone numbers, email addresses, and current events.
For further support information, refer to the Technical Support and Professional Services
appendix. To comment on National Instruments documentation, refer to the National
Instruments Web site at ni.com/info and enter the Info Code feedback.
Chapter 1
Vision Assistant Environment
Launching and Exiting Vision Assistant .......................................................................... 1-1
Vision Assistant Environment .......................................................................................... 1-1
Features..................................................................................................................... 1-2
Getting Help ..................................................................................................................... 1-3
Vision Assistant Context Help and Tooltips ............................................................ 1-3
National Instruments Web Site................................................................................. 1-3
Vision Assistant Scripts............................................................................................ 1-3
Chapter 2
Introduction to Image Processing with Vision Assistant
Getting Started in Vision Assistant .................................................................................. 2-1
Acquiring Images in Vision Assistant .............................................................................. 2-6
Opening the Acquisition Window ............................................................................ 2-6
Snapping an Image ................................................................................................... 2-8
Grabbing an Image ................................................................................................... 2-9
Acquiring a Sequence of Images .............................................................................. 2-9
Chapter 3
Using Particle Analysis to Analyze the Structure of a Metal
What Is Particle Analysis?................................................................................................ 3-1
Tutorial ............................................................................................................................. 3-1
Loading Images into Vision Assistant...................................................................... 3-2
Preparing an Image for Particle Analysis ................................................................. 3-2
Examining the Image........................................................................................ 3-2
Filtering the Image............................................................................................ 3-4
Examining the Results of the Filtering ............................................................. 3-4
Separating Particles from the Background with Thresholding................................. 3-5
Modifying Particles with Morphological Functions................................................. 3-6
Isolating Circular Particles ....................................................................................... 3-7
Analyzing Circular Particles..................................................................................... 3-8
Testing the Particle Analysis Script.......................................................................... 3-9
Saving the Particle Analysis Script .......................................................................... 3-11
Estimating Processing Time ..................................................................................... 3-11
Creating a LabVIEW VI........................................................................................... 3-11
Creating a C Program ............................................................................................... 3-12
Chapter 4
Using Gauging for Part Inspection
What Is Gauging? ............................................................................................................. 4-1
Tutorial.............................................................................................................................. 4-1
Loading Images into Vision Assistant ...................................................................... 4-3
Finding Measurement Points Using Pattern Matching ............................................. 4-3
Finding Edges in the Image ...................................................................................... 4-6
Taking the Measurements ......................................................................................... 4-7
Analyzing the Results ....................................................................................................... 4-10
Chapter 5
Using a Coordinate System for Part Inspection
What Is a Coordinate System?.......................................................................................... 5-1
Tutorial.............................................................................................................................. 5-2
Loading Images into Vision Assistant ...................................................................... 5-2
Defining a Feature on which to Base a Coordinate System ..................................... 5-2
Defining a Coordinate System .................................................................................. 5-4
Checking for Presence .............................................................................................. 5-4
Testing the Dental Floss Script ................................................................................. 5-5
Saving the Dental Floss Script.................................................................................. 5-7
Analyzing the Results ....................................................................................................... 5-7
Appendix A
Technical Support and Professional Services
Glossary
Index
Conventions
The following conventions are used in this manual:
» The » symbol leads you through nested menu items and dialog box
options to a final action. The sequence Options»Settings»General
directs you to pull down the Options menu, select the Settings item,
and select General from the last dialog box.
bold Bold text denotes items that you must select or click in the software,
such as menu items and dialog box options. Bold text also denotes
parameter names.
monospace Text in this font denotes text or characters that you should enter from
the keyboard, sections of code, programming examples, and syntax
examples. This font is also used for the proper names of disk drives,
paths, directories, programs, subprograms, subroutines, device names,
functions, operations, variables, filenames, and extensions.
Related Documentation
The following documents contain information that you may find helpful as you use this manual.
To access the NI Vision Assistant documentation, select Start»All Programs»National
Instruments»Vision Assistant.
• NI Vision Development Module Release Notes—Contains information about new
functionality, minimum system requirements, installation instructions, and descriptions of
the documentation for NI Vision Assistant.
• NI Vision Assistant Help—Contains descriptions of the Vision Assistant features and
functions and provides instructions for using them. To open the help file in Vision Assistant,
select Help»Online Help.
• NI Vision Concepts Manual—Describes the basic concepts of image analysis, image
processing, and machine vision. This document also contains in-depth discussions about
imaging functions for advanced users.
The algorithm is recorded in a script file, which contains the processing functions and relevant
parameters for an algorithm that you prototype in Vision Assistant. Using the LabVIEW VI
Creation Wizard, you can create a LabVIEW VI that performs the prototype that you created in
Vision Assistant.
Note You must have LabVIEW 7.1 or later and the NI Vision 8.6 Development
Module or later installed to use the Vision Assistant LabVIEW VI Creation Wizard.
For more information about LabVIEW VI creation, refer to the Creating a LabVIEW VI section
of Chapter 3, Using Particle Analysis to Analyze the Structure of a Metal.
Using the C Code Creation Wizard, you can generate a C function that performs the prototype
that you created in Vision Assistant. For more information about C Code creation, refer to the
Creating a C Program section of Chapter 3, Using Particle Analysis to Analyze the Structure of
a Metal.
Note If you have LabWindows™/CVI™ 7.0 or later, you can create a project for the
generated C code.
You also can implement the algorithm defined by the Builder file into any development
environment, such as Microsoft Visual Basic, using the NI Vision machine vision and image
processing libraries.
Features
Vision Assistant offers the following features:
• Script window—Records a series of image processing steps and the settings you use for
each of those steps. You can run scripts on single images or in a batch to analyze a collection
of images. You also can modify and save scripts. Refer to Figure 2-2, Processing an Image,
for an example of the Script window.
• Image Browser—Contains all of the images currently loaded in Vision Assistant. You can
select an image to process by double-clicking it in the Image Browser. Refer to Figure 2-1,
Image Browser, to view images loaded into the Image Browser.
• Processing Window—Updates the image as you change parameters. Because this view
immediately reflects the changes you have made in the Setup window, you can continue
modifying parameters until you get the result you want. Refer to Figure 2-2, Processing an
Image, to view an image loaded into the Processing window.
• Processing Functions Window/Setup Window—Displays a list of image processing
functions you can use to develop an algorithm, or displays parameters that you can set for
an image processing function. Each function available through the Processing Functions
window has a Setup window in which you set the parameters for that function. Refer to
Figure 2-3, Thresholding an Image, to view an example of the Setup window for the
Threshold function.
• Reference Window—Displays the image source as you manipulate it in the Processing
window. Refer to Figure 2-2, Processing an Image, to view an image in the Reference
window.
• Solution Wizard—Displays a list of industries and corresponding quality-assurance tasks
that those industries perform. The wizard loads an NI Vision-based solution for the task you
select.
• Performance Meter—Estimates how long a script will take to complete on a given image.
• LabVIEW VI Creation—Creates a LabVIEW VI corresponding to the algorithm you
prototype in Vision Assistant. Based on the options you select, the LabVIEW VI Creation
Wizard creates a new VI that implements the image processing steps of the current script
or of a saved script file.
• C Code Creation—Creates a C file corresponding to the algorithm you prototype in Vision
Assistant. Based on the options you select, the C Code Creation Wizard creates a C function
that implements the image processing steps of the current script.
• Builder File—ASCII text file that lists the Visual Basic functions and parameters for the
algorithm you prototyped in Vision Assistant.
Getting Help
As you work with Vision Assistant, you may need to consult other sources if you have questions.
The following sources can provide you with more specific information about NI Vision software
and NI image acquisition devices.
Vision Assistant also provides tooltips in the Vision Assistant interface. Tooltips briefly describe
buttons in the toolbar, Script window, Reference window, or Image Browser when you move the
cursor over the buttons.
From the NI Vision site, you can locate information about new NI Vision features, machine
vision problems and solutions, and selecting the appropriate NI Vision hardware, cameras,
lenses, and lighting equipment for applications.
The NI Developer Zone, available at ni.com/zone, is the essential resource for building
measurement and automation systems. The NI Developer Zone includes the latest example
programs, system configurators, tutorials, and technical news, as well as a community of
developers ready to share their own techniques.
In this short example, you load images into Vision Assistant and perform a threshold on them.
Thresholding isolates objects, keeping those that interest you and removing those that do not.
Thresholding also converts the image from a grayscale image, with pixel values ranging from
0 to 255, to a binary image, with pixel values of 0 or 1.
6. Click Browse Images in the upper right corner of the Vision Assistant window.
Vision Assistant loads the image files you opened into the Image Browser, as shown in
Figure 2-1. The Image Browser provides information about the selected image, such as
image size, location, and type.
2 9
3 4 5 6 7 8
You can view images in either thumbnail view, as shown in Figure 2-1, or in full-size view,
which shows a single full-size view of the selected image.
7. Click the Thumbnail/Full-Size View Toggle button to view the first image in full size.
8. Click Process Images in the upper right corner of the Vision Assistant window to begin
processing images. Vision Assistant loads the image into the Processing window, as shown
in Figure 2-2.
Tip You can double-click an image in the Image Browser to being processing it in
the Processing window.
Tip The Reference window displays the original version of the image as you
manipulate it in the Processing window.
9. Click Threshold in the Grayscale tab of the Processing Functions, or select Grayscale»
Threshold. The Threshold Setup window opens in the lower left corner of the Vision
Assistant window, as shown in Figure 2-3.
The Threshold Setup window displays a histogram. A histogram counts the total number of
pixels at each grayscale value and displays the data in a graph. From the graph, you can see
if the image contains distinct regions of certain grayscale intensities. Thresholding isolates
these regions from the rest of the image. For example, if the image contains bright objects
on a dark background, you can isolate the objects and remove the background by selecting
Bright Objects from the Look For drop-down list and setting a minimum threshold value
close to 255 (white).
The Processing window displays a preview of the default threshold operation, Manual
Threshold, using the current set of parameters. The pixels depicted in red have intensities
that fall inside the threshold range. The threshold operator sets their values to 1. The pixels
depicted in gray have values outside the threshold range. The threshold operator sets their
values to 0.
10. To threshold this image, set the Minimum value to 130 to select all of the objects.
Tip You may need to manipulate the Minimum value several times to find the one
that works best. Rather than enter a number in the Minimum field, you can select the
value using the pointer on the histogram. Adjust the pointer until all of the objects
you want to select are red.
The thresholding step is recorded in the Script window. The script records the processing
operation and all of its parameters. If you must run the same operation on other images, you
can save the script and use it again.
14. Select File»Save Script As, and name the script threshold.scr.
If you find another image that you must threshold similarly, run this script on the image
using the following steps:
a. Load the image.
b. Select File»Open Script, select threshold.scr, and click Open.
c. Click the Run Once button in the script window.
Try experimenting with different options and images. For example, you can perform a
particle analysis to find the area that each object in this image occupies. If you need help
with any specific image processing operation, click the How To tab or the Controls tab in
the Context Help window.
Using Vision Assistant, you can acquire images with various National Instruments Smart
Cameras, digital and analog frame grabbers, DCAM-compliant IEEE 1394 cameras, and Gigabit
Ethernet (GigE) Vision cameras. For information about driver software, refer to the NI Vision
Acquisition Software Release Notes.
Configure your image acquisition devices in National Instruments Measurement & Automation
Explorer (MAX). For information about configuring image acquisition devices in MAX, refer to
the NI Vision Acquisition Software Release Notes.
If you do not have an image acquisition device and the corresponding driver software, you can
use the Simulate Acquisition step to simulate a live acquisition by displaying a sequence of
images. You can interact with the simulation module as you would with a live acquisition. For
example, you can stop the sequence at any frame, capture the image, and send the image to the
Image Browser for processing.
If you already have Vision Assistant running, click Acquire Images in the toolbar.
Vision Assistant displays the Acquisition functions, as shown in Figure 2-5.
3. Click Acquire Image. The Setup window displays the NI Vision devices and channels
installed on the computer. For example, Figure 2-6 shows that the NI PCI-1410 is installed.
Note The hardware devices listed in the Setup window vary according to the devices
installed.
Snapping an Image
Complete the following steps to acquire and display a single image.
1. Select File»Acquire Image.
2. Click Acquire Image in the Acquisition function list.
3. Select the appropriate device and channel or port.
4. Click the Acquire Single Image button to acquire a single image with the image
acquisition device and display it.
5. Click the Store Acquired Image in Browser button to send the image to the Image
Browser.
Grabbing an Image
Complete the following steps to acquire and display a continuous set of images.
1. Select File»Acquire Image.
2. Click Acquire Image in the Acquisition function list.
3. Select the appropriate device and channel or port.
4. Click the Acquire Continuous Images button to acquire and display images in continuous
mode at the maximum rate.
5. Click the Acquire Continuous Images button again to stop the acquisition and display the
last acquired image.
Tip You can acquire a region of interest (ROI) within the full-sized image. If you
draw an ROI on an image while grabbing it, the image reduces to the ROI. You can
refine the acquired area again by selecting another region of interest, or you can
return to the full-sized image by clicking the image.
6. Click the Store Acquired Image in Browser button to send the image to the Image
Browser.
Note You must have Microsoft Excel installed to complete some steps in this
tutorial.
You perform a particle analysis to detect connected regions or groupings of pixels in an image
and then make selected measurements of those regions. Using particle analysis, you can detect
and analyze any two-dimensional shape in an image. With this information, you can detect flaws
on silicon wafers, detect soldering defects on electronic boards, or locate objects in motion
control applications when there is significant variance in part shape or orientation.
Tutorial
This tutorial demonstrates finding the area of circular particles in a metal. As you perform this
analysis, Vision Assistant records all of the processing operations and parameters in a script.
You run the script on other images to test the particle analysis algorithm.
To find the total area of circular particles, you perform the following image processing steps:
• Filter the image to sharpen edges and ease the separation of the particles from the
background.
• Threshold the image to isolate the appropriate particles.
• Fill holes that appear in the particles after thresholding.
• Remove all objects touching the border so that you remove partial particles.
• Use a particle filter to find all circular particles and remove non-circular particles.
• Perform a particle analysis to find the total area occupied by circular particles.
Tip The Preview Image window displays all selected images in a sequence. To
view the images at a different rate, adjust the slide to the right of the Preview Image
window.
6. Click Open. Vision Assistant loads the image files, which represent microscopic views of
pieces of metal. The first image, Metal1.jpg, loads in the Processing window.
2. Click Line Profile in the Image tab of the Processing Functions palette, or select
Image»Line Profile to open the Setup window. Notice that the Line Tool is automatically
selected in the toolbar and is active.
Tip ROIs are context sensitive, and you can easily adjust their location in the image
or the position of their center points. You can also adjust the position of the ROI in
the image by using the arrow keys on the keyboard.
In Figure 3-1, the areas labeled 1 represent the edges of the particles. Notice that the edges
of the particles have a slope. The more shallow the slope, the greater variation you have in
detecting the exact location of the edge. As you change the threshold level in images with
shallow-sloped particle edges, you might inadvertently change the shape or size of the
particle. In the Filtering the Image section of this chapter, you use the
Convolution-Highlight Details filter under Filters in the Grayscale tab of the Processing
Functions palette to define the edges of the particles and increase the slope.
The area labeled 2 in Figure 3-1 is a fluctuation in pixel values, which might be caused by
brighter and darker pixels in the center of the particles or it might also be edges of a hole in
the particle. Later, you will threshold the image to make all of the pixels in the particles the
same pixel value and then perform a morphological operation on the image to fill any holes
left in the particles.
4. Click Cancel. You do not need to add the Line Profile step to the script because it was for
investigational purposes only.
Complete the following steps to select a range of brighter pixels for analysis.
1. Click Threshold in the Grayscale tab of the Processing Functions palette, or select
Grayscale»Threshold.
The Threshold Setup window displays a histogram. A histogram counts the total number of
pixels in each grayscale value and graphs it. From the graph, you can tell if the image
contains distinct regions of a certain grayscale value. You also can select pixel regions of
the image.
2. To threshold this image, set the Minimum value to 130.
Notice that the particles of interest (circular and non-circular) are highlighted in red. When
you apply the threshold, everything highlighted is set to 1, and all other pixels are set to 0.
Tip Rather than enter a number in the Minimum field, you can select the value
using the pointer on the histogram. Adjust the pointer until all of the objects you want
to select are red.
Use the following steps to apply two morphological functions to the image. The first function
fills holes in the particles and the second removes objects that touch the border of the image.
1. Click Adv. Morphology in the Binary tab of the Processing Functions palette, or
select Binary»Adv. Morphology.
2. Enter Fill Holes in the Step Name control.
3. Select Fill holes from the list.
4. Click OK to add this step to the script.
5. Click Adv. Morphology in the Binary tab of the Processing Functions palette, or
select Binary»Adv. Morphology.
6. Enter Remove Border Objects in the Step Name control.
7. Select Remove border objects to remove any objects that touch the border of the image.
Refer to Figure 3-4 to see what the image looks like after applying morphological functions
to the image.
8. Click OK to add this step to the script.
6. Click OK to add this step to the script. The image now contains only circular particles, as
shown in Figure 3-5.
Tip When you click a particle, the measurement results for that particle are
highlighted in blue. When you click the results for a particle, the particle is
surrounded by a green rectangle in the Processing window.
8. Click OK to record the particle analysis and add the step to the script.
Tip Rather than returning to the Image Browser, you can navigate through the
images in the Image Browser from the Reference window. Click the Next Image and
Previous Image buttons until you see the image you want to process and then click
the Make Image Active button to move that image into the Processing window.
Figure 3-6a shows the original image, Metal3.jpg. Figure 3-6b shows the image after the
particle analysis processing. Notice that two circular particles are removed from the image
during processing because they are touching each other. You need to adjust the Threshold
step to separate the particles.
a. b.
6. Adjust the minimum threshold value until the particles are clearly separated. A minimum
value of 150 works well.
7. Click OK.
8. Click Run Once to rerun the script. Notice that only the circular particles now appear in the
final processed image.
Refer to the NI Vision Assistant Help for more information about the Vision Assistant batch
processing functionality.
Creating a LabVIEW VI
Vision Assistant features a wizard that creates a LabVIEW VI that implements the different
steps of the script.
Note You must have LabVIEW 7.1 or later and the NI Vision 8.6 Development
Module or later installed to use the Vision Assistant LabVIEW VI Creation Wizard.
Note If several versions of LabVIEW and NI Vision are installed on the computer,
the wizard searches the machine and displays a list of the available LabVIEW and
NI Vision versions you can use to create the VI.
Note If you have LabVIEW open, you cannot create a VI for a different version
of LabVIEW. For example, if you have LabVIEW 8.0.1 open and you select
LabVIEW 8.2 in the LabVIEW VI Creation Wizard, the wizard returns an error
when you click Finish.
Creating a C Program
Vision Assistant features a wizard that creates C code that implements the different steps of the
script.
Note You must have the NI Vision 8.6 Development Module or later installed to use
the Vision Assistant C Code Creation Wizard.
Tip If you have LabWindows/CVI installed, and you want to use it to compile and
test the C code, select the Add Files to LabWindows/CVI Project option.
What Is Gauging?
Components such as connectors, switches, and relays are small and manufactured in high
quantity. While human inspection of these components is tedious and time consuming, vision
systems can quickly and consistently measure certain features on a component and generate a
report with the results. From the results, you can determine if a part meets its specifications.
Tutorial
In this tutorial, you analyze images of pipe brackets to determine if the brackets meet their
physical specifications. A pipe bracket is a metal piece of hardware used to secure long, slender
parts, such as a tube of bundled wires.
The goal is to measure angles and distances between features on the brackets and determine if
those measurements fall within a tolerance range. Figure 4-1 illustrates the measurements and
the acceptable values for them.
Side View
Bracket Distance
362 to 368 pixels
Edge 1
3
5
1 2
Bracket Angle
178 to 181 Degrees Width Center
Edge 2
Top View
Width Center is the center of the bracket and becomes the vertex of Bracket Angle. Bracket
Angle measures the angle of the arms of the bracket and determines if the bracket arms are
aligned properly. Bracket Distance measures the length in pixels between two manufactured
holes in the bracket. Bracket Distance also determines if the bracket arch is the appropriate
height and curvature.
As you perform this analysis, Vision Assistant records all of the processing operations and
parameters in a script that you can run on other bracket images to determine which are good and
which are defective.
Tip The Preview Image window displays all selected images in a sequence. To view
the images at a different rate, adjust the slide to the right of the Preview Image
window.
6. Click Open to load the image files into Vision Assistant. The first image, Bracket1.jpg,
loads in the Processing window.
2. Select Pattern Matching in the Machine Vision Processing Functions tab, or select
Machine Vision»Pattern Matching.
3. Click New Template. The NI Vision Template Editor opens.
4. With the Rectangle Tool, click and drag to draw a square ROI around the left hole in the
image, as shown in Figure 4-2. The ROI becomes the template pattern.
5. Click Next.
6. Click Finish. Learning the template takes a few seconds. After Vision Assistant learns the
template, the Save Template as dialog box opens.
7. Navigate to <Vision Assistant>\Examples\bracket.
8. Save the template as template.png. The Pattern Matching Setup window displays the
template image and its path.
9. Click the Settings tab.
10. Set Number of Matches to Find to 1.
11. Set the Minimum Score to 600 to ensure that Vision Assistant finds matches similar,
but not identical, to the template.
12. Enable the Subpixel Accuracy checkbox.
13. Make sure Search for Rotated Patterns is not selected to set the search mode to shift
invariant. Use shift-invariant matching when you do not expect the matches you locate to
be rotated in their images. If you expect the matches to be rotated, use rotation-invariant
matching.
14. With the Rectangle Tool, draw an ROI around the left side of the bracket, as shown in
Figure 4-3. Be sure that the region you draw is larger than the template image and big
enough to encompass all possible locations of the template in the other images you analyze.
Drawing an ROI in which you expect to locate a template match is a significant step in
pattern matching. It reduces the risk of finding a mismatch. It also allows you to specify the
order in which you want to locate multiple instances of a template in an image and speeds
up the matching process.
When you draw the ROI, Vision Assistant automatically locates the template in the region
and displays the score and location of the match. Notice that the score for the match is 1000.
The score for this match is perfect because you made the template from the same region of
the image.
15. Click OK to save this step to the script.
16. Select Pattern Matching in the Machine Vision tab of the Inspection steps, or
select Machine Vision»Pattern Matching.
17. Click Load from File and open the template you just saved.
18. Click the Settings tab.
19. Set Number of Matches to Find to 1.
20. Set the Minimum Score to 600 to ensure that Vision Assistant finds matches that are
similar, but not identical, to the template.
21. Enable the Sub-pixel Accuracy checkbox.
22. With the Rectangle Tool, draw an ROI around the right side of the bracket, as shown in
Figure 4-4. Vision Assistant automatically locates the template in the region bound by the
rectangle and displays the score and location of the match.
The score of the second match is not a perfect 1000, but it is high enough for you to consider
it a match to the template.
23. Click OK to add this step to the script.
Tip To draw a straight line, press and hold the <Shift> key as you draw the line.
Look at the edge strength profile. The sharp transitions in the line profile indicate edges.
Notice that the number of edges found is displayed under the edge strength profile.
6. Click OK to add this step to the script.
3. Click points 3 and 4 in the image to obtain the Width Center measurement, which specifies
the center of the bracket width.
When you select a point in the image, Vision Assistant places a check mark next to the
corresponding point in the Caliper Setup window.
Tip If you have trouble finding the points, click the Zoom In tool in the Tools palette
to magnify the image. Magnification factors are displayed in the lower left corner of
the Processing window. 1/1 specifies 100% magnification (default). 2/1 specifies a
slightly magnified view, and 1/2 specifies a slightly demagnified view.
Tip Instead of selecting points from the image, you can select points by
double-clicking their entries in the Available Points listbox.
4. Click Measure to compute the center of the bracket width and add the Mid Point
measurement to the results table, as shown in Figure 4-6.
5. Click OK to add this step to the script.
6. Select Caliper in the Machine Vision tab, or select Machine Vision»Caliper again. The
center of the bracket width appears as point 5.
7. Select Distance in the Geometric Feature listbox.
8. Click points 1 and 2 in the image to find the Bracket Distance, which measures the length
between the manufactured holes in the bracket and determines if the bracket arch is the
appropriate height.
9. Click Measure to compute the distance between the bracket holes. The distance
measurement is added to the results table, as shown in Figure 4-7.
10. Select Angle Defined by 3 Points in the Geometric Feature listbox. Click points 1, 5, and
2, in this order, to find the next measurement—Bracket Angle—which measures the angle
of the bracket arms with respect to a vertex at point 5, as shown in Figure 4-8.
11. Click Measure to compute the angle of the bracket arms and add the measurement to the
results table.
Figure 4-8 shows the image with Bracket Distance and Bracket Angle selected on the image and
displayed in the results table.
12. Click OK to add these caliper measurements to the script and close the caliper window.
13. Select File»Save Script As, and save the script as bracket.scr.
7. Click the Folder Path button. Navigate to the directory in which you want to save the
results file, and click Current Folder.
8. Enter bracket_results.txt in the File Prefix control. Because you are logging all the
results to one file, the File Prefix is the name of the individual results file. If you were
logging the results for each image to a separate file, File Prefix would be the prefix
associated with the index for each results file.
9. Click OK.
10. Click Run to run the script on all the images in the Image Browser and log the results.
11. Click OK to close the Batch Processing finished notification.
12. Navigate to the directory path specified in step 7, and open bracket_results.txt.
13. Compare the Bracket Distance and Bracket Angle measurements in the results file to the
values in Table 4-1.
Table 4-1 shows the acceptable ranges for the bracket measurements and the actual values
you might see for each bracket image. Notice that Bracket1, Bracket2, and Bracket3
are the only ones that meet the specifications. The bold values for the other brackets
indicate which measurements caused them to fail.
Note The results may vary slightly based on the template you chose for the pattern
matching step and the position of the line you drew for the edge detection step.
Refer to the NI Vision Assistant Help for more information about the Vision Assistant batch
processing functionality.
If the object under inspection is always at the same location and orientation in the images you
need to process, defining a region of interest is simple. However, the object under inspection
often appears shifted or rotated within the images you need to process. When this occurs, the
region of interest needs to shift and rotate with the parts of the object you are interested in.
In order for the region of interest to move in relation to the object, you need to define a
coordinate system relative to a feature in the image.
A coordinate system is specified by its origin and the angle its x-axis makes with the horizontal
axis of the image. Assign a coordinate system based on how you expect the object to move in the
image. If the object is going to only translate in the horizontal or vertical directions, you need
only to select a feature whose location can represent the origin of the coordinate system. The
angle is 0 by default. If the object is going to translate and rotate, you need to select features that
can represent the location of the origin and angle of the coordinate system.
Tutorial
In this tutorial, you analyze images of dental floss holders to determine if the holders contain
toothpaste and a wire.
Tip The Preview Image window displays all selected images in a sequence. To view
the images at a different rate, adjust the slide to the right of the Preview Image
window.
3. Draw a rectangle around the base of the dental floss, as shown in Figure 5-1. This region
becomes the pattern matching template.
4. Click Next.
5. Click Finish. The Save Temple as dialog box opens.
6. Navigate to <Vision Assistant>\Examples\dental floss, where <Vision
Assistant> is the location to which Vision Assistant is installed.
7. Save the template as template.png. The Pattern Matching Setup window displays the
template image and its path.
8. Click the Main tab.
9. Enter Find Dental Floss Base in the Step Name control.
10. Click the Settings tab.
11. Enable the Subpixel Accuracy checkbox.
12. Enable the Search for Rotated Patterns checkbox.
13. Set the Angle Range +/– control to 180.
14. Click OK to save this step to the script.
Notice the Origin and X-Axis Angle lists. Match 1, the match location of the previous Find
Dental Floss Base step, is the default origin of the coordinate system because it is the only
location point created by previous steps in the script.
4. Click OK to save this step to the script.
Notice that the Quantify step supports a variety of different tools that enable you to draw
different shaped regions of interest, such as a point, line, broken line, freehand line, rectangle,
oval, polygon, and freehand region. These tools are available in the Vision Assistant toolbar.
4. Click the Polygon Tool in the Vision Assistant toolbar.
5. Draw three regions of interest that enclose the wire and the two sections of toothpaste in the
dental floss holder, as shown in Figure 5-2. Click and drag repeatedly to select a polygon
region. Double-click to complete the polygon.
2. Click the Make Image Active button to move that image into the Processing window. The
dental floss base should be found in the new image and the regions of interest for the
toothpaste and wire should reposition correctly based on the coordinate system.
Verifying your algorithm on new images is an important step in creating a robust algorithm
because it helps you determine if your regions of interest are positioned correctly and helps you
determine acceptable values for the results in the Quantify step.
You may need to adjust some parameters for the algorithm to work properly on other dental floss
images. For example, if the base of the dental floss holder is not found in an image, the region
of interest will not reposition correctly. If that happens, open the Find Dental Floss Base
step and adjust the minimum score and, if necessary, adjust the search area.
To determine acceptable values, you can compare the Mean Value measurements in the
Quantify step results. The Mean Value displays the mean value of the pixel intensity in the
regions of interest you drew in the Quantify step.
Table 5-1 shows the acceptable values for the dental floss measurements and the actual values
you might see for each dental floss image. For Mean Value 1 and Mean Value 2, which are the
mean values for the toothpaste regions of interest, an acceptable value is 100 or greater. Mean
values less than 100 signify that the toothpaste is missing from the dental floss holder. Notice
that Dental Floss 2, Dental Floss 4, and Dental Floss 8 are missing toothpaste.
For Mean Value 3, which is the mean value for the wire region of interest, an acceptable value
is greater than 20, but less than 40. A mean value below 20 signifies that the wire is missing from
the dental floss holder. Notice that Dental Floss 6 and Dental Floss 8 are missing wires. A mean
value above 40 signifies a frayed wire. Dental Floss 7 has a frayed wire.
Note The results may vary slightly based on the position of the regions of interest
you drew for the Quantify step.
Acceptable Values Greater than 100 Greater than 100 Between 20–40
Refer to the NI Vision Assistant Help for more information about the Vision Assistant batch
processing functionality.
You also can visit the Worldwide Offices section of ni.com/niglobal to access the branch
office Web sites, which provide up-to-date contact information, support phone numbers, email
addresses, and current events.
B
binary image An image in which the objects usually have a pixel intensity of 1 (or
255) and the background has a pixel intensity of 0.
C
caliper (1) A function in Vision Assistant that calculates distances, angles,
circular fits, and the center of mass based on positions given by edge
detection, particle analysis, centroid, and search functions; (2) A
measurement function that finds edge pairs along a specified path in
the image. This function performs an edge extraction and then finds
edge pairs based on specified criteria such as the distance between
the leading and trailing edges, edge contrasts, and so forth.
coordinate system A reference location (origin) and angle in an image that regions of
interest can relate to when positional and angular adjustments of the
region of interest are necessary. A coordinate system is depicted by
two lines representing the orientation and direction of its two axes.
D
definition The number of values a pixel can take on, which is the number of
colors or shades that you can see in the image.
digital image An image f (x, y) that has been converted into a discrete number of
pixels. Both spatial coordinates and brightness are specified.
E
edge Defined by a sharp change (transition) in the pixel intensities in an
image or along an array of pixels.
F
function A set of software instructions executed by a single line of code that
may have input and/or output parameters and returns a value when
executed.
G
gauging Measurement of an object or distances between objects.
H
histogram Indicates the quantitative distribution of the pixels of an image per
gray-level value.
I
image A two-dimensional light intensity function f (x, y) where x and y
denote spatial coordinates and the value f at any point (x, y) is
proportional to the brightness at that point.
image file A file containing pixel data and additional information about the
image.
image processing Encompasses various processes and analysis functions that you can
apply to an image.
inspection The process by which parts are tested for simple defects such as
missing parts or cracks on part surfaces.
intensity The sum of the Red, Green, and Blue primary colors divided by
three: (Red + Green + Blue)/3.
K
kernel Structure that represents a pixel and its relationship to its neighbors.
The relationship is specified by weighted coefficients of each
neighbor.
L
LabVIEW Laboratory Virtual Instrument Engineering Workbench—Program
development environment based on the G programming language.
LabVIEW is used commonly for test and measurement
applications.
luma The brightness information in the video picture. The luma signal
amplitude varies in proportion to the brightness of the video signal
and corresponds exactly to the monochrome picture.
M
machine vision An automated application that performs a set of visual inspection
tasks.
N
neighbor A pixel whose value affects the value of a nearby pixel when an
image is processed. The neighbors of a pixel are usually defined by
a kernel or a structuring element.
NI-IMAQdx The National Instruments driver software for IEEE 1394 and
GigE Vision cameras.
P
palette The gradation of colors used to display an image on screen, usually
defined by a color lookup table.
pattern matching The technique used to locate quickly a grayscale template within a
grayscale image.
Q
quantitative analysis Obtaining various measurements of objects in an image.
R
resolution The number of rows and columns of pixels. An image composed of
m rows and n columns has a resolution of m n.
S
shift-invariant A pattern matching technique in which the reference pattern can be
matching located anywhere in the test image but cannot be rotated or scaled.
T
template Color, shape, or pattern that you are trying to match in an image
using the color matching, shape matching, or pattern matching
functions. A template can be a region selected from an image, or it
can be an entire image.
threshold Separates objects from the background by assigning all pixels with
intensities within a specified range to the object and the rest of the
pixels to the background. In the resulting binary image, objects are
represented with a pixel intensity of 255 and the background is set
to 0.
Tools palette Collection of tools that enable you to select regions of interest,
zoom in and out, and change the image palette.
V
value The grayscale intensity of a color pixel computed as the average of
the maximum and minimum red, green, and blue values of that
pixel.
H M
help magnifying an image, 4-7
Context Help window, 1-3 Measurement & Automation Explorer
National Instruments Web site, 1-3 (MAX), 2-6
technical support, A-1 measurements for gauging. See gauging
tooltips, 1-3 morphology, 3-6
Heywood Circularity Factor particle
filter, 3-7 N
histogram, 2-4, 3-5 National Instruments
in Threshold Setup window, 2-4 support and services, A-1
Web site, 1-3
I
image acquisition, 2-6 O
See also acquiring images opening images, 2-1, 3-2, 4-3
image acquisition device, 1-1, 1-3, 2-6, 2-8
Image Browser
accessing from the toolbar, 3-9 P
definition, 1-2 part inspection, 4-1
full-size view, 2-2 particle, 3-1
important elements (figure), 2-2 particle analysis
thumbnail view, 2-2 analyzing circular particles, 3-8
image processing, thresholding images, 2-4 definition, 3-1
image segmentation estimating processing time, 3-11
grayscale threshold, 2-4, 3-5 examining image, 3-2
images, loading for gauging, 4-3 filtering, 3-4
installing, Vision Assistant, 1-1 introduction, 3-1
instrument drivers (NI resources), A-1 isolating circular particles, 3-7
isolating circular particles, 3-7 modifying particles with morphological
functions, 3-6
morphology, 3-6
K opening images, 3-2
KnowledgeBase, A-1 overview, 3-1
particle filter, 3-7
L preparing images for processing, 3-2
LabVIEW, 3-9 saving the script, 3-11
VI creation, 1-2, 3-11 separating particles from
LabWindows/CVI, 3-9 background, 3-5
C code creation, 1-2, 3-12 testing the script, 3-9
launching Vision Assistant, 1-1 thresholding, 3-5
line profile, 3-2 particle filter, 3-7
line tool, 3-2 particles, separating from background with
loading images, 2-1, 3-2, 4-3, 5-2 thresholding, 3-5
W
Web resources, A-1
Web support from National Instruments
getting help for NI Vision, 1-3
windows
Context Help, 1-3
Embedded Help, 1-2
Processing, 1-2
Processing Functions, 1-2
Reference, 1-2, 2-3, 3-9
Script, 1-2, 2-5
Setup, 1-2
Z
Zoom In tool, 4-7