Particle analysis analyzes complete objects rather than a part of an object. So, it is difficult to measure the size of a specific part in an object. On the other hand, the method using edge detection can measure the dimension of parts of objects. In this section, the edge detection method is extended to two dimensions (2D) to measure an object's dimensions. One way to do this is to cover a two-dimensional area with many search lines over which edge detection is performed. The measurement of an object's dimension in this manner can give accurate dimensional information since the outline of an object can be obtained by using a set of line ROIs to define 2D area. The Clamp function based on 2D edge detection is often used to detect locations that define the maximum or minimum length of a part of an object. Then, Caliper function can be used to determine the distances between edges. An example VI of measuring dimension by using a Clamp function can be found from the following folder:
Figure 7.1 shows the front panel of this dimension measurement example. In this example the maximum horizontal size of a hole in an object can be measured. Note that if you change the location and size of the ROI, you can measure the dimension of different parts of the object.
In this section, you will learn how to use Vision Assistant Express to measure dimensions of objects in an image.
7.1.1 Find Circular Edge Function
Complete the following steps in Vision Assistant Express to measure the dimension of circle 1 using Find Circular Edge.
- Build a VI for continuous image acquisition, as seen in Figure 7.3 . Note that this part will be modified later to be used in an Event structure.
- Save one of the acquired images from the Image display on the front panel.
- From the function palette, drag Vision Assistant Express onto the block diagram, as seen in Figure 7.3 . You will then see the Vision Assistant Express wizard window.
- Select the Find Circular Edge function from Processing Functions:Machine Vision»Find Circular Edge.
- Move the mouse near the center of circle 1 and define an annular (circular) ROI around circle 1 with the left mouse button, as seen in Figure 7.4. There are two circles in an annular ROI: the inner circle should be placed inside of the circle 1 and outer circle should be placed outside of the circle 1.
- As seen in Figure 7.5, it is possible to measure the center location and radius of circle 1 by using the Find Circular Edge function.
7.1.2 Clamp Function
The Clamp function can be used to measure the radius as well as the location of circle 2. The reason for using Clamp function here is to help readers understand different dimension measurement approaches. Note that the Find Circular Edge function could be more effectively used to measure circle 2 instead of the Clamp function. In the case of using the Clamp function, the image should be converted to 8 bit grayscale image (or binary image) since the clamp function is based on edge detection techniques. So, you need to convert color image to grayscale image via color plane extraction function (Processing Functions: Color» Color Plane Extraction» HSL-Luminance Plane) prior to using Clamp function.
Complete the following steps to measure circle 2 based on Clamp function.
- Select the Clamp function from Processing Functions:Machine Vision»Clamp. Then, select the Clamp (Rake) Setup parameters, as seen in Figure 7.6.
- Select Horizontal Max Caliper from Process selection and in this case set the value for gap to 5, as seen in Figure 7.6 and . You may want to select different parameters according to your needs. Tips for selecting these parameters are discussed in the following.
Search Lines: Process
Table 7.1 Clamp process.
|Horizontal max caliper||Horizontal min caliper||Vertical max caliper||Vertical min caliper|
|The maximum length in the horizontal direction is measured||The minimum length in the horizontal direction is measured based on detected edge||The maximum length in the vertical direction is measured||The minimum length in vertical direction is measured based on detected edge|
Search Lines: Gap
The Gap among ROI lines for edge detection can be modified. As seen in Table 7.2, smaller gap can reduce the distance among ROI lines for edge detection. Small gaps give better results in terms of accuracy. However, it may not be efficient in terms of computation time because there will be more edge data to be processed. So, the proper value for gaps needs to be selected considering accuracy and efficiency.
- Select OK and you can confirm the overlaid results using Find Circular Edge and Clamp to measure circle 1 and circle 2, respectively, as seen in Figure 7.8.
Table 7.2 Clamp gap setup.
|Gap: 2||Gap: 4||Gap: 6|
7.1.3 Caliper Function
To measure the distance between circle 1 and circle 2, select the Caliper function from Processing Functions: Machine Vision. Figure 7.9 shows the Caliper setup. You will need to select a measurement item from Figure 7.9 . Select a geometric feature of caliper from the available features, as summarized in Table 7.3.
Table 7.3 Measurement items for caliper.
|Distance||Midpoint||Perpendicular projection||Lines intersection||Angle from horizontal|
|Angle from vertical||Angle defined by three points||Angle defined by four points||Bisecting line||Mid line|
|Center of mass||Area||Line fit||Circle fit||Ellipse fit|
To measure the distance between the two circles using Caliper function, complete the following two steps:
- Step 1: Finding Center of Circle 2
- Select Mid Point from the Geometric Feature list, as seen in Figure 7.10 . By selecting the Mid-Point between the two points, you can obtain the center location of circle 2.
- Select the Point 1 and Point 2 of circle 2, as seen in Figure 7.10 , which corresponds to horizontal maximum and minimum points.
- Select Measure as seen in Figure 7.10 to obtain the midpoint of Point 1 and Point 2. The midpoint corresponds to the center location of circle 2, as seen in Figure 7.11. As a result, you can get X and Y center position of circle 2, as seen in Figure 7.11.
- Select OK to proceed to next step.
- Step 2: Finding Distance between Circle 1 and Circle 2
- Select Caliper from Processing Functions: Machine Vision»Caliper to measure the distance between two circles.
- Select Distance as seen in Figure 7.12 from the Geometric Feature.
- Select Center (item No. 1) and Mid Point (item No. 4) to measure the distance between the circles. Here, Mid Point corresponds to the center of circle 2.
- Select Measure .
As a result of the measurement, you can see the distance between two circle centers, as seen in Figure 7.13.
7.2.1 Vision Assistant Express VI for Dimension Measurement
After confirming the results from Vision Assistant, create controls and indicators by clicking Select Controls>>. Here, two ROI Descriptors (Figure 7.14 and ) and one caliper results (Figure 7.14 ) are selected as controls and indicator, respectively, as seen in Figure 7.14. If you then select Finish, the Vision Assistant Express VI will have inputs and outputs that can be accessed from the block diagram, as seen in Figure 7.15.
As seen in Figure 7.15, there are two ROI Descriptors for the annulus and rectangle ROIs as input terminals of the Vision Assistant created VI. The ROIs will be defined interactively from the Image display on the front panel during execution. The methods for creating the two different ROIs will be discussed in Section 7.2.2.
7.2.2 ROI Array
To effectively deal with more than two different ROIs, we recommend the use of a ROI array. Note that there are two ROIs, which are different in type, location, and size to measure the center of two circles using different functions.
You can create a ROI array by using the following processes shown in Figure 7.16.
- Place an Array control in the front panel (step 1 in Figure 7.16).
- From Control palette, go to IMAQ Vision Controls from the Vision palette and select ROI Descriptor ( ) (step 2 in Figure 7.16).
- Drag the ROI Descriptor and drop it into the Array control (step 3 in Figure 7.16).
The ROI array is used to handle more than one ROI descriptors from the main program. The first element in the ROI array is the Annulus-type ROI for Find Circular Edge function, whereas the second element of the ROI array is a Rectangle type for the Clamp function. If wrong types of ROI are connected to controls of Vision Assistant Express in Figure 7.15, there will be errors during the measurement process.
7.2.3 Front Panel of Main VI
Figure 7.17 shows the front panel of main program to measure the distance between two circles. Note that the approach used in this example may not be the preferred method for your application. So, you may want to modify this proposed method according to your applications.
The main feature of the program is that two different types of ROI are used to measure the locations of two circles. For this purpose, a ROI array is used, as seen in Figure 7.17 . In the main VI, one type of ROI can be added by user selection on image display. To show more than one ROI on the image display, all the ROI elements in the ROI array are grouped, as seen in Figure 7.17 . The details of dealing with multiple ROIs will be discussed later.
Figure 7.17 shows the Boolean controls to add or delete a ROI from ROI array. By clicking the Boolean control (ADD), a user-selected ROI on the image display can be added to the ROI array. To select different types of ROI, the ROI tools can be used. In this example, annular and rectangular types of ROI can be selected from ROI tool, as seen in Figure 7.17 and . Finally, the Caliper function is used to calculate the distance (Figure 7.17 ) between two circles if the Boolean switch (Image Processing) in Figure 7.17 is true.
To calculate the distance between the two circles, the following steps needs to be taken.
- Select Annulus ROI by using .
- Draw out the ROI on the circle of on the image display.
- Click ROI ADD in in order to add annulus-type ROI to ROI array.
- Select rectangle ROI .
- Draw out the rectangle ROI on the circle of on the image display.
- Click ROI ADD to add the rectangle ROI to ROI array.
- Activate Image Processing (Boolean control) in .
- The result of the distance measurement is then displayed in .
7.2.4 Block Diagram of the Main VI
Figure 7.18 shows the block diagram for the circle distance measurement. The Vision Assistant Express VI, described in Section 7.2.3, is used for image analysis. Here, an Event structure is used to coordinate the acquisition and analysis of the images, as seen in Figure 7.18.
Figure 7.18 shows the Timeout event. If no value is connected at , the default value will be −1 and the timeout case will never be processed. In this example, the value is set to 300. As a result, the timeout event will be executed once every 300 ms if there are no other events. In this way, one frame per 300 ms is shown on Image front panel display. In addition, if the Boolean control of Image Processing is true, then the image analysis within Vision Assistant Express VI () will be executed to measure the distance between the circles. Note that image conversion from color to grayscale is included in the Vision Assistant Express function. So, if the Vision Assistant Express is executed, the color image is automatically changed to grayscale. If you want to keep original image, you will need to allocate additional image memory with the IMAQ Create function and connect it to the image destination (Image Dst) input of Vision Assistant Express VI in Figure 7.18 .
If Boolean control of Image Processing is false, then only the acquired image will be shown on front panel (Image display) without any image analysis, as seen in Figure 7.19.
Figure 7.20 shows the stop event. This event occurs when the value of stop (Boolean) changes, the program will be terminated.
The method to create ROI arrays will now be discussed. Figure 7.21 shows the event structure to create and add an ROI to the ROI array. The ROI ADD event shown in Figure 7.21 will be executed when the ROI ADD Boolean control on the front panel changes its value when the user clicks on it. In Figure 7.21 and show the local variable for the ROI Array. Figure 7.21 shows the property node of the Image to retrieve the current ROI information.
As seen in Figure 7.21, the current ROI information of the image can be added to the ROI array by using the Build Array function in Figure 7.22. Note that when Building Array function is used, the Concatenation input option should be selected (right click on the Building Array icon to select the Concatenation option).
The ROI Array needs to be reformed in a way that is compatible with the ROI data contained in the Image display. For this purpose, IMAQ Group ROIs function (Figure 7.21 ) is used. This will result in the multiple ROIs being displayed in the Image display on the front panel. The IMAQ Group ROIs function can be found in function palette: Vision and Motion»Vision Utilities»Region of Interest (Figure 7.23).
The grouped ROIs can be supplied as an input into the Image display by using Image ROI property node (with write option), as seen in Figure 7.21 . In this way, you can see more than one ROI on the image display.
In some cases, the size of the ROI array may need to be reduced. For this purpose, to reduce the size of the ROI array, an ROI Delete event can be created, as seen in Figure 7.24. In the ROI delete event, the ROI element with highest index will be deleted from the ROI array.
Figure 7.24 and show the local variable of ROI Array. By using a Delete from Array function , an element of ROI array with maximum index is deleted and thereby the size of the array can be reduced by 1. The reduced ROI array can be grouped using IMAQ ROI Group function. The grouped ROI can be displayed on the front panel Image display with the use of Image ROI property node in .
In this example, the number of elements in ROI array was two since two ROIs are required to measure the distance between circles. However, you can define as many as ROIs according to your applications by using the ROI arrays.
Use the Caliper function to calculate the distances (d1, d2, d3) among three holes as seen in Figure 7.25. The image can be found from C:\Program Files\National Instruments\Vision\Examples\Images\Holes.tif.