This section describes methods for the quantitative analysis of objects in binary images, including counting, measuring distances, and analyzing other object properties.
Particle Measurements
The following functions deal with various kinds of particle measurements, such as counting, clamping (measuring distances), and making other more complex measurements.
Counting Objects
The function IMAQ Count Objects is again a complete image analysis application, similar to the function IMAQ Find Horizontal Edge we used in Exercise 5.6. It is possible to adjust various parameters, such as the search rectangle, the type of objects (bright or dark), whether holes in objects should be filled, or whether objects touching the border of the image are to be ignored. Because the function requires a gray-level image as input, the threshold value also has to be specified.
Exercise 5.12: Counting Objects.
From Exercise 5.6 (one of the "locating edges" exercises), replace the IMAQ function by IMAQ Count Objects (you will find the VI in Motion and Vision / Machine Vision / Count and Measure Objects). Add controls for the search rectangle and a cluster control for the settings, similar to the previous exercises. See Figure 5.36 for the panel and Figure 5.37 for the diagram.
The bottom-left corner of Figure 5.36 shows the objects to count in IMAQ Vision Builder. The function IMAQ Count Objects shows the bounding box for each object, the center of each object, and the search area specified by the Search Rectangle cluster control.
Figure 5.36. Counting Objects in Gray-Scaled Images
Figure 5.37. Diagram of Exercise 5.12
Note that not only the big objects, such as the bear's face, are found, but also very small objects, which are hardly visible in the left part of Figure 5.36. The range within objects that should be counted is adjusted by the controls Minimum Object Size and Maximum Object Size.
Measuring Distances (Clamping)
For our next exercise we examine a group of functions located in Motion and Vision / Machine Vision / Measure Distances. They are IMAQ Clamp Horizontal Max , IMAQ Clamp Horizontal Min , IMAQ Clamp Vertical Max , and IMAQ Clamp Vertical Min .
Again, these functions are complete vision applications and provide a number of outputs and image overlays, similar to the "locating edge" examples. Using these VIs, we can measure the extensions of objects in gray-scaled images, either in a horizontal or vertical direction.
Exercise 5.13: Clamping Distances.
Modify Exercise 5.6 (one of the "locating edges" exercises) by replacing the IMAQ function by IMAQ Clamp Vertical Max . Add controls for the search rectangle and a cluster control for the settings, as in the previous exercises.
In a next step, add a case structure to the VI, so that it is possible to select the desired function. Add a Text Ring control so that you can specify the function through the front panel. You can also add a numeric indicator for displaying the measured distance. See Figure 5.38 for panel, diagram, and a first result showing the measuring of vertical maximum distances.
Figure 5.38. Measuring Vertical Maximum Distances
Naturally, the term "objects in gray-scaled images" I used a few sentences before is not correct, and you already know why: it is necessary to specify a threshold level to convert the gray-scaled image to a binary one. After that, you will find areas with pixel value 1 and other areas with pixel value 0; it depends on you, which of them you call "objects" and which of them "background."
The clamp functions use parameters called Contrast, Filter Width, Subsampling Ratio, and Steepness to define the contours of the objects that must be measured. See Figures 5.39, 5.40, and 5.41 for measuring vertical minimum distances and horizontal maximum and minimum distances, respectively.
Figure 5.39. Measuring Vertical Minimum Distances
Figure 5.40. Measuring Horizontal Maximum Distances
Figure 5.41. Measuring Horizontal Minimum Distances
Complex Particle Measurements
The next two functions we discuss in this section, IMAQ BasicParticle and IMAQ ComplexParticle , can be used for a detailed analysis of particles (objects) in binary images. The basic particle function provides only the following information:
Exercise 5.14: Basic Particle Analysis.
Start with Exercise 4.16 and add the function IMAQ BasicParticle . Change the Selection Values control to a constant, and filter the image so that not too many particles remain in your image. Add an indicator to display Basic Particle Reports .
Figure 5.42 shows the panel of the exercise, the filtered image, and the labeled particles. I used IMAQ Vision Builder for the labeling, but you could include the labeling in this exercise. See also Figure 5.43 for the diagram window.
Figure 5.42. Basic Particle Analysis of a Filtered Image
Figure 5.43. Diagram of Exercise 5.14
For our next exercise, which uses the function IMAQ ComplexParticle , we simply replace the function IMAQ BasicParticle in Exercise 5.14. The Complex Particle function provides the following parameters:
Exercise 5.15: Complex Particle Analysis.
Replace the IMAQ Vision function IMAQ BasicParticle in Exercise 5.14 with IMAQ ComplexParticle and modify the indicator, here called Complex Reports, to display the results. See Figure 5.44 and Figure 5.45.
Figure 5.44. Complex Particle Analysis of a Filtered Image
Figure 5.45. Diagram of Exercise 5.15
IMAQ ChooseMeasurements , another function of this group, filters the reports generated either by IMAQ BasicParticle or by IMAQ ComplexParticle , based on a selection parameter and minimum and maximum values. We need not try this function in an exercise here, because our VIs already provide particle filtering with the function IMAQ ParticleFilter .
To calculate the whole range of particle parameters, or at least one of the more complex ones we mentioned in Chapter 4, you use the function IMAQ ComplexMeasure .
Exercise 5.16: Choosing Additional Measurements.
Add the IMAQ Vision function IMAQ ChooseMeasurements to Exercise 5.15. Provide a control for choosing the parameter you want to measure, and provide a numeric 1D-array for the results. See Figure 5.46 and Figure 5.47.
Figure 5.46. Calculating Other Complex Particle Parameters
Figure 5.47. Diagram of Exercise 5.16
In the next pages we discuss in more detail the parameters that can be measured by IMAQ ComplexParticle or calculated by IMAQ ChooseMeasurements . You can also find these details in [4].
Equation 5.1
Equation 5.2
Equation 5.3
Equation 5.4
Equation 5.5
the x coordinate of G is therefore
Equation 5.6
which is the average location of the central points of the horizontal segments in a particle [4].
Equation 5.7
Equation 5.8
Equation 5.9
Equation 5.10
Equation 5.11
Equation 5.12
Equation 5.13
Equation 5.14
Figure 5.48. Intercept and Chord Particle Measurements
Equation 5.15
if the particle area A is
Equation 5.16
Equation 5.17
Equation 5.18
Equation 5.19
Equation 5.20
Equation 5.21
Equation 5.22
Equation 5.23
Equation 5.24
Image Calibration
Sometimes it is necessary to convert the x and y dimensions of an image into real units; for example, in our motor image, we can measure some "real" distances on the motor itself.
Before we start a new exercise, let us look at the relevant functions in IMAQ Vision Builder. Load a binary motor image ( dc_motor_bin3.png ) and select Image / Simple Calibration. Use the menu now displayed to define two main topics:
Figure 5.49. Calibrating the Motor Image
With the motor image selected, draw a vertical line from the top to the bottom of the motor, thus specifying the smallest possible distance; this action returns an (image) distance of about n = 150 pixels. The real distance is about d = 15.4 mm, which you must enter in the appropriate control.
The new dimension is now displayed in the coordinate system. The image is now ready for simple or complex particle analysis, which is based on user units; for example, measuring height, width, area, perimeter, and some other parameters in real-world units.
Exercise 5.17: Image Calibration.
Here, we try image calibration in a LabVIEW exercise: In Exercise 5.16, insert the function IMAQ Set Simple Calibration (you can find it in Motion and Vision / Vision Utilities / Calibration) between IMAQ Particle Filter (which is not really necessary here) and IMAQ WindDraw . Provide an additional control for setting the grid description. As mentioned above, it is not necessary here to change orientation and origin of the coordinate system. See Figure 5.50 and Figure 5.51.
Figure 5.50. Setting a Simple Pixel Calibration
Figure 5.51. Diagram of Exercise 5.17
We can calculate the correct factors "X Step" and "Y Step" in Exercise 5.17 by using the values we obtained from IMAQ Vision builder. The value f for both directions is
Equation 5.25
See also Figure 5.50.
Another possibility is to use a grid image , showing circular dots specifying the distortion of an image (Figure 5.52). Calibration of the image (we use IMAQ Vision Builder here) is done by the following steps:
Figure 5.52. Grid Calibration with IMAQ Vision Builder
Shape Matching |
Introduction and Definitions
Image Acquisition
Image Distribution
Image Processing
Image Analysis
About the CD-ROM