Chapter 8: Dimension Measurement Using Coordinate System – Practical Guide to Machine Vision Software: An Introduction with LabVIEW

Dimension Measurement Using Coordinate System

To measure the dimensions of an imaged object, a ROI is used to define the measurement location as discussed in previous chapters. In most cases, the object under inspection may shift and/or rotate in the viewing field of the video image. If a static ROI does not incorporate the entire object under investigation, the dimension may not be measured. For this case, the ROI location will need to be shifted and rotated according to the objects location. To enable this dynamic ROI location, a reference coordinate system can be used to define the measurement area around the object relative to the reference location of the object. The reference coordinate system is based on a characteristic feature of the object. To locate a reference coordinate system relative to the object, pattern matching or edge detection can be used. The ROI defined with respect to the reference coordinate system is then used to measure the dimension of a part of the object.

The example using a reference coordinate system can be found from the following folder:

As seen in Figure 8.1, a reference coordinate can be located irrespective of any shift and/or rotation of the object in an image via pattern matching. From the reference coordinate, the ROI used for measurement can be automatically located on a part of the object that is of interest.

Figure 8.1 Example VI for coordinate system.

8.1 Measurement Based on a Reference Coordinate System Using Vision Assistant Express

Figure 8.2 Example image for dimension measurement.

8.1.1 Pattern Matching

If the location of object in the image is not initially known, a distinct feature of the object needs to be located to define a reference coordinate system. In this example, pattern matching is used to find the location of object and determine the coordinate system.

As a first step, create a VI for continuous image acquisition, as discussed in Chapter 2 (Figure 2.12). Then, one of the acquired images is saved as a file for image processing using Vision Assistant Express. The Vision Assistant Express VI can be dragged down onto the block diagram for image analysis.

The color image should be converted to a grayscale image prior to pattern matching by using Color plane Extraction function from Processing Functions: Color. Here, the Luminance Plane from HSL is selected as discussed previously.

To define a reference coordinate system, a subfeature of the object is used with pattern matching to locate the object. Note that the selected subfeature should have parts that are not symmetric so that the angle of the subfeature can be uniquely determined in the pattern matching process. In this example, the end part of the object is selected as a template image for use in searching for object's location. To define reference coordinate system, complete the following steps.

  1. Select Processing Functions: Machine Vision»Pattern matching.
  2. Select New Template from the pattern matching setup.

    Note that object may be rotated. To effectively select rotated object, the Rotated Rectangle ROI tool in Figure 8.3 is used. In this way, the end part of the rotated object can be selected as the template image for pattern matching, as seen in Figure 8.3 .

  3. Select Next and then Finish (Figure 8.4 ) if the template image is acceptable and save the template file.
  4. Select the Settings tab seen in Figure 8.5.
  5. Select a ROI (Figure 8.6 ) to define the search area for the matched pattern. Later, two more local ROIs will be defined to measure the dimensions of the object based on the reference coordinate.
  6. Check that the results of the search are correct as in Figure 8.6 . If the results are not correct, adjust pattern matching settings in . For details, refer to Chapter 5. Click on OK to proceed to the next step.

Figure 8.3 Selection of template image.

Figure 8.4 Template editor.

Figure 8.5 Template tab for pattern matching setup.

Figure 8.6 Pattern matching results.

8.1.2 Coordinate System

The next step is to define the reference coordinate system based on the matched patterns. This will be accomplished in the following steps:

  1. Select Set Coordinate System from Processing Functions: Image section, as seen in Figure 8.7.
  2. Selecting Horizontal, Vertical, and Angular Motion from the Mode selections allows the pattern matching function to search for rotated and shifted instances of the pattern in the image, as seen in Figure 8.8. Note that Pattern Matching 1-Match 1 is reported in the Origin and X-Axis Angle box. Pattern Matching 1-Match 1 is the result of the previous pattern matching and is used for defining the origin and reference coordinate system. After finishing the setup, the coordinate system, which has the name of Set Coordinate System 1, will be created.

Figure 8.7 Set Coordinate System.

Figure 8.8 Set Coordinate System setup.

8.1.3 Dimension Measurement Using the Clamp Function

  1. The Clamp function will be used here to measure distance between the object's edges (Figure 8.9). Here, the Clamp functions for dimension measurement can be found from Processing Function: Machine Vision. Note that there are other measurement functions that can be used depending on the object shapes to be measured.
  2. Select the Reposition Region of Interest and Set Coordinate System 1 from the main tab of Clamp setup, as seen in Figure 8.10, in order to use the dynamically defined reference coordinate system from above. In this way, the dimensions of the object will be measured relative to the reference coordinates.
  3. Select the Clamp tab from the Clamp (Rake) setup. A Clamp Rake ROI can be placed on the image. Using the control points on the ROI, rotate, scale, and move this ROI into position as seen in Figure 8.11 .
  4. Select Horizontal Min Caliper from the Process selections (Figure 8.11 ) to measure the gap distance. Since the coordinate system has been redefined dynamically by the previous step (Set Coordinate System, Section 8.1.2), the position of the clamp ROI will move with respect to the new reference coordinate system based on the position of the object.
  5. Select the OK button if all the other setting values are acceptable. Then, you will see that clamp distance can be measured based on the dynamically determined reference coordinate system.
  6. Select the OK button if the measurement is acceptable.

Figure 8.9 Clamp function.

Figure 8.10 Reference coordinate system for Clamp function.

Figure 8.11 Clamp setup.

8.1.4 Measurement of Circle Edge

As a next step, you need to measure the circular edge.

  1. Select Find Circular Edge setup from Processing Function: Machine Vision. Make sure that reference system is correctly selected and the repositioned region of interest is selected as seen in Figure 8.12. Then, select OK.
  2. Draw out the ROI for Find Circular Edge as seen in Figure 8.13 and check the settings in Figure 8.13 to obtain the best circle results.
  3. Select OK. You will now see the two measurement results overlaid on the image, as seen in Figure 8.14 .
  4. Click on Select Controls (Figure 8.14 ) to set the controls and indicators we will need in a LabVIEW VI. In this example, the ROI Descriptor for pattern matching is selected as a control and Clamp Distance and Fitted Circle are selected as indicators, as seen in Figure 8.15 and . After selecting Finish , a VI having the specified controls and indicators is created (Figure 8.16).

Figure 8.12 Find Circular Edge setup.

Figure 8.13 Settings for Find Circular Edge setup.

Figure 8.14 Overlaid measurement results.

Figure 8.15 Selection of controls and indicators.

Figure 8.16 Vision Assistant Express VI.

8.2 Conversion of Vision Assistant Express to a Standard VI

We will now modify the resulting function created with Vision Assistant Express. In order to do this, we first need to convert the Vision Assistant Express function to a standard VI by right mouse clicking on the VI icon and selecting Open Front Panel from the pop-up window. Then, a standard VI will be created from Vision Assistant.

Figure 8.17 shows a part of the resulting VI that performs pattern matching (Figure 8.17 ) and defines the reference coordinate (Figure 8.17 ) based on the matched pattern. Now, by creating an indicator of Matches (output of IMAQ Match Pattern VI indicated at ) and connecting it to the terminal of the VI, the match results will be available for the creation of an indicator on the main VI's front panel. Also, the match results will be used to overlay location information on the image.

Figure 8.17 LabVIEW code (Coordinate setting via pattern matching).

Figure 8.18 shows the block diagram of the main VI for measuring the clamp gap and inner circle edges. Figure 8.18 shows the converted standard VI with file name of Note that the created output terminal for the pattern matching results is connected to an overlay VI shown in Figure 8.18 .

Figure 8.18 Main VI for measurement.

Note that the Image ROI property node shown in Figure 8.18 retrieves the ROI information from the Image display to define the search area for the pattern matching process. The matched pattern is then used to define the reference coordinate system. For this to be successful, the ROI area should be set large enough to find the part of object that has the reference pattern. If you do not connect this ROI descriptor, the created VI will use the default constant ROI descriptor that was defined in pattern matching setup during the Vision Assistant setup and may not be appropriate for variable imaging situations.

To overlay the pattern matching results on the image display, the previously created Draw Pattern Matches (Figure 5.14) was modified, as seen in Figure 8.19. The main difference is that the Clear Overlay function is not used because it would delete the overlay for Clamp Distance and Find Circle Edge, which were included from Vision Assistant.

Figure 8.19 Modified overlay VI.

Figure 8.20 shows the results of dimension measurement based on the reference coordinate system. To validate the VI, the object can be moved and rotated as seen in Figure 8.20a and b. The VI can measure object dimensions irrespective of the object's location and rotation. Therefore, the coordinate system based on pattern matching is useful to measure dimensions of objects when you do not have any prior information on the location of the object in the image.

Figure 8.20 Results of dimension measurement based on coordinate system. (a) Inclusive ROI. (b) Noninclusive ROI.

You may notice that the circular fit results are slightly different according to the location. This is due to the camera axis not being located perpendicular to the object. The perspective errors may be corrected by using the calibrated image, which will be discussed in Chapter 14.

Portions of the object in Figure 8.20b are located outside the ROI. Nevertheless, the clamp gap (Distance) and circle radius (Radius) were possible since the searched parts of the pattern are still within the ROI.

Exercise 8.1

Use the rotated images from C:\Program Files\National Instrument\Vision\Examples\Images\Rotate. Select one of the images from the folder and make reference coordinate at the bump part (Figure 8.21). By using the reference coordinate, calculate the size of bump part of other images with different rotated angle.

Figure 8.21 Size measurement of the bump part in rotated images.