# InspectEdge Functions

The InspectEdge Vision Tools are utilized to perform advanced edge analysis, examining edges of objects for deviations, such as cracks, nicks, dents, or crimps. These tools are typically used to develop detailed information about the precise locations of features within or outside an object, and to determine if there are defects on those features.

The InspectEdge function locates edges or edge pairs in the image using the edge mode method, in which edge peaks are detected within the individual Calipers using a 1D kernel. An edge model is created, using the InspectEdgeForDefect, InspectEdgePosition, or InspectEdgeWidth functions, that defines the ideal edge or edge pairs, and subsequent edge candidates are compared to the edge model to determine if there are defects or gaps in the edge candidate.

Once you have determined the location and orientation of the edge or edge pair of interest in the image, the following steps are performed in applying the tools:

- Specify a ROI and Calipers that enclose the edges or edge pairs of interest, and Calipers, Minimum Contrast and Edge Width parameter values that isolate the edges of interest, using the InspectEdge function.
- Define an edge model that describe the edge or edge pair of interest using the InspectEdgeForDefect, InspectEdgePosition and/ or InspectEdgeWidth functions.

## InspectEdge Edge Detection

The first step in using the InspectEdge Vision Tools is to specify a region of interest in the image that you want to apply the tool. The InspectEdge function relies on a carefully defined ROI to isolate the relevant edge information from the image.

Specify a ROI to determine where in the image the tool should detect the edge or edge pairs in one of the following ways:

- Use the InspectEdge Region parameter to define the location, size, angle, bend and/ or rotation.
- Construct an external ROI, such as an EditMaskedRegion or EditPolylinePath.

When positioning your ROI, ensure that the edges of interest are parallel to the search direction of the ROI, and that the ROI encloses as much of the edge or edges as possible, while also excluding unnecessary or unwanted noise from the ROI.

Within the ROI of the InspectEdge function, a Caliper array is used to produce a 1D representation of the portion of the image that contains the edges of interest. This 1D image contains not only the edges of interest, but also other edges caused by noise and unwanted information in the original image. Applying the Caliper, Edge Width and Minimum Contrast parameters in InspectEdge to the 1D image increases the strength of the edges of interest while at the same time decreasing image noise.

### Defining Edge Models with InspectEdgeForDefect, InspectEdgePosition, or InspectEdgeWidth

Once the InspectEdge function has located the edges in the image, the InspectEdgeForDefect, InspectEdgePosition, or InspectEdgeWidth functions are used to create an edge model of the edges expected to be encountered during the inspection. The edge(s) in the image are called edge candidates, while the ideal edge is called the edge model. Creating an edge model involves defining the best-fit line type, type of edge to be detected (single edge or edge pairs), edge transitions, edge scoring rules, line-fit rules and the types of defects and/or gaps to inspect.

InspectEdgeForDefect is used to create a best-fit line based on the edge model, and inspect for deviations from the edge model. InspectEdgePosition is used to determine the position of edges in relation to the edge model, and report deviations from the model, while also optionally creating a best-fit line. InspectEdgeWidth is used to examine a pair of edges for deviations in the distance between them.

For all three of the functions, after the referenced InspectEdge function has divided the ROI into an array of Calipers, each Caliper is evaluated and the edges within are scored to determine which edge should be selected. For position defects, a line is fit based on each found edge, and defects are determined by comparing the found edge to the line fit for variances outside of tolerances. For width defects, the distance between the two edges found within the Caliper are calculated to determine their distance, and defects are determined by comparing the distance to the expected range.

### Evaluating Results

For each edge pattern candidate in the image that fails to adequately match the edge model, the functions can return the following information, if specified:

- The position of the edge pattern candidate relative to the line fit.
- The size, area and position of any defects or gaps found in the edge pattern candidate.

In addition, you can use the other associated InspectEdge Vision Data Access functions functions to gather additional information to perform your own processing and analysis of the data generated by the InspectEdge Vision Tools.