Extract and Analyze Contours
Contour analysis involves three steps. First, curves are extracted from the image. Next, the curves are connected based on the connection parameters. Finally, the step selects a single connected curve to represent the contour. Refer to the NI Vision Concepts Help for more information about the process of contour analysis.
Main Tab
In the Step Name textbox, enter a descriptive name for the step.
Verify that the Reposition Region of Interest option is enabled if you want to link the region of interest specified in this step to a previously defined coordinate system.
Link the region of interest to a coordinate system if the position of the object under inspection changes from image to image, and you need to adjust the position of the region of interest to match the new location of the object.
Draw a ROI around an object in the image with contours that you want to analyze.
Extract Contour
Modify the Curve Extraction controls to improve curve detection, if necessary.
Modify the Contour Selection controls, if necessary, so that the step selects the correct contour for your application.
Modify the Curve End Point Connection controls, if necessary, to change how the step connects individual curves to produce contours.
Modify the Distance Range control to only connect curves with end points separated by a distance within the specified range. The following figure illustrates distance between end points: distance between end points
Distance
Modify the Angle Range control to only connect curves when the difference between the angle of the curves, measured at the end points, is within the specified range. Values range from 0 degrees to 180 degrees. The following figures illustrate how the angle of a curve is calculated: distance between end points distance between end points
A B
In Figure A, the difference between angle A and angle B is close to 0. In Figure B, the difference between angle A and angle C is close to 90 degrees.
Modify the Connectivity Range control to only connect curves when a line extended from the end point of one curve passes the end point of another curve within the specified distance. The following figure illustrates how connectivity is calculated: distance between end points
Distance between end point A and a
line extended from end point B
Distance between end point A and end
point C
End point A is closer to end point C than to end point B. Specify a connectivity range to connect end point A to end point B instead of end point C.
Modify the Gradient Direction Range control to only connect curves when the difference between the gradient angle of each curve is within the specified range. The following figure illustrates two curves with opposite gradient angles:
gradient difference between curves
Specify a high gradient range to connect the curves.
Note The Contour Selected indicator displays the color used to indicate the selected contour in the image.
Analyze Curvature
Enable the Compute Curvature checkbox if you want to compute the curvature of the selected contour. Adjust the Kernel Size value to change the size of the kernel used to compute the curvature profile of the contour. The Curvature Profile table displays the curvature profile for the selected contour. Refer to the NI Vision Concepts Help for more information about how the contour analysis algorithm computes curvature.
Complete the following steps if you want to classify individual curves along the selected contour:
Click the add range Add Range button to create a new curvature range.
Refer to the Curvature Profile and identify the curvature range that you want to classify. Tip A red line indicates the currently selected position in the curvature profile. A cross indicates the currently selected position on the selected contour in the displayed image. Use these indicators to identify the curvature range that you want to classify.
Adjust the Min and Max values to include the curvature range that you want to classify.
Click the Color for the selected curvature range to change the color used to indicate the class in the image.
Compare Contours
Enable the Compare Contour checkbox if you want to compare the selected contour to a fitted contour or a template contour.
Select To Fitted Contour to compare the selected contour to a fitted contour.
Select Line, Circle, or Ellipse to fit an ideally shaped contour to data points in the selected contour. Modify the Pixel Radius to control how the contour is fitted to the selected contour. Tip The step uses the following process to fit a contour. The step assumes that a point is part of the fitted contour if the point lies within a user-defined pixel radius from the fitted contour. Then the step fits a line to a subset of points that best describe the selected shape.
Select B-Spline or Polynomial to fit a contour to data points in the selected contour. Modify the Control Points