# Flaw Detection

The Flaw Detection Vision Tools, SurfaceFlaw, and DetectFlaw, FlexFlawModel and TrainFlawModel, are used to perform advanced pattern match analysis to verify the presence or absence of defects.

Note: The Flaw Detection Vision Tools are not supported on the In-Sight D900 Series Vision Systems.

The SurfaceFlaw Detection Vision Tool is used to detect small flaws based upon pixel intensity variations, without the use of a trained model. This tool is designed for detecting flaws such as scratches, nicks, tears, stains or chips.

The DetectFlaw, FlexFlawModel and TrainFlawModel Flaw Detection Vision Tools create a model based upon a "golden" or perfect part, and then compare the model against acquired images using an advanced pattern matching algorithm to determine if there are any flaws, such as missing edges, surface scratches or logos were printed incorrectly.

In-Sight vision systems perform detailed flaw detection analysis using the Flaw Detection Vision Tool's functions:

- SurfaceFlaw: Detects local intensity variations within an image to determine if flaws are present.
- DetectFlaw: Creates the parameters to determine if a flaw exists or not when comparing acquired images against the model.
- FlexFlawModel: Creates optional Flex algorithms to compensate for process variations.
- TrainFlawModel: Creates the model of the "golden" part.

Note: The FlexFlawModel function must reference a data structure output by a TrainFlawModel function. The DetectFlaw function may reference a data structure output by either a TrainFlawModel or DetectFlaw function.

## About the In-Sight Flaw Detection Tools

The Flaw Detection Vision Tools are composed of two groups of tools, the SurfaceFlaw function and the DetectFlaw, FlexFlawModel and TrainFlawModel functions.

### SurfaceFlaw Flaw Detection Vision Tool

#### Overview

The SurfaceFlaw function is designed to detect areas of local intensity and color variations which are flaws in the production process. The function uses an internal filtering operation to first highlight edges and areas with sudden color or greyscale variations, before applying blob analysis to determine whether or not flaws are present.

SurfaceFlaw is a stand-alone function, and does not require the use of a model, simplifying its setup and improving its execution time. Due to not incorporating a model, the function is able to account for run-time lighting variations and accurately detect flaws. However, it does not have the ability to compensate for possible variations, as the DetectFlaw, FlexFlawModel and TrainFlawModel functions can, so it can not adjust for process variations in a part. Therefore, SurfaceFlaw is best suited to applications where a part should have a uniform area to be inspected, such that any sudden change in intensity will be classified as a defect. If the part will have intensity variations, the other Flaw Detection functions should be able to account for the variations.

Note: The SurfaceFlaw function does accept a Mask data structure output by the Mask function. This allows the function to only inspect specified areas within an image.

### DetectFlaw, FlexFlawModel and TrainFlawModel Flaw Detection Vision Tools

#### Overview

The DetectFlaw, FlexFlawModel and TrainFlawModel Flaw Detection Tools are designed to perform advanced pattern matching analysis, verifying whether or not defects are present. The functions combine model "stretching" (teaching the function to compensate for possible variations) and image subtraction to create detailed models that are compared against acquired images, determining whether a defect exists in the acquired image. Within this architecture, the functions provide the ability to dynamically update the model during run-time.

The functions, when combined together, are capable of performing the following types of inspections:

- Boundary Defects — Ensuring that the part/object maintains the same shape.
- Surface Defects — Ensuring that the part/object does not have any stains or scratches.
- Print Inspections — Ensuring that the part/object's silk screened logo was printed correctly and without defects.

#### Building the Model

As with all applications, first, a database of images of the part, containing the part in both its "good" and "bad" states is loaded. To begin using the Flaw Detection Tools, first load an image of the object/part that will be inspected that illustrates the part/object in its "golden" or perfect state. This ensures that all of the correct features of the object/part are included in the original model. After the image has been loaded, the TrainFlawModel function is added to the spreadsheet, and either the function's internal Region or a reference to an external region or path is specified to define the object/part in the image. Once all of the parameters have been adjusted to adequately define the model, the function will then store all of the data about the model.

#### Detecting Defects

With the trained model now in place, the DetectFlaw function can be used to classify defects in the object/part as it appears in acquired images. The DetectFlaw function compares the model data stored in the TrainFlawModel function against acquired images to determine if there are area and/or edge defects in the object/part. Area inspections verify whether there are defects such as scratches or stains on the surface of the object/part. Edge inspections verify whether there are extra or missing edges, or that the boundary of the object/part is consistent. Combining area and edge defects provides the highest degree of inspection verification.

The DetectFlaw function also contains controls to dynamically adjust the mask during run-time to ignore certain flaws.

#### Flexing the Model

Optionally, if the object/part may undergo distortions or process variations, the FlexFlawModel function may be used to create Flex algorithms to compensate for the distortions and process variations. The FlexFlawModel allows the model to be "stretched," which involves modifying the model to allow a broader range of possible variations in the part, to ensure that the DetectFlaw function does not classify the variation as a defect.

Definition of terms:

- Edge Pixel: A pixel in an image that lies on the boundary between two areas of different pixel values.
- Edge Segment: A continuous boundary between areas of dissimilar pixel values. An Edge Segment is represented by a list of Edge Pixels (i.e. "Edge Features").
- Flex: The displacement of Edge Pixels and Edge Segments, which may be caused by positioning errors, lens or perspective distortions, registration errors or other normal process variations.
- Enclosed Segment and Enclosed Segment Flex: An Enclosed Segment is an Edge Segment with the same beginning and ending points; Enclosed Segment Flex is the displacement of an Enclosed Segment.
- Line Segment Flex: A Line Segment is a portion of an Edge Segment, which may or may not be enclosed; Line Segment Flex is the displacement of a Line Segment.
- Pixel Flex: The displacement of an Edge Pixel.
- Flex Resolution: The scaling factor applied to the model image and the mask image when corrections for flex are applied. A higher resolution will more accurately handle non-linear distortion, but will consume more memory.
- Mask/Masking: A collection of pixel locations which are to be ignored during processing. Pixels which are masked will never generate a defect, regardless of the pixel value.
  Note: The Mask/Masking functionality in the Flaw Detection tools is not the same as those applied in the EditCompositeRegion function. The EditCompositeRegion function is typically used to define an irregular Region of Interest (ROI) and exclude areas of the image, while the masking used by the Flaw Detection tools is computed to determine the pixel greyscale gradient values when creating the model.
- Area Defects: A type of flaw that is found by comparing the pixels of a trained Model Image against an acquired image, and verifying whether the pixel value (greyscale or color intensity) are the same. Area defects are typically blob-like, and may include discoloration, smears, stains or streaks.
- Missing Edge Defects: A type of flaw that occurs when a previously trained Edge Segment is not found in the acquired image. Missing edge defects typically include such defects such as changes in a part's contour or a missing feature.
- Extra Edge Defects: A type of flaw that occurs when an Edge Segment appears in the acquired image that wasn't present in the trained Edge Segment. Extra edge defects typically include defects such as extra features, scratches or tears.
- Model Image: The image that was saved during training. The Model Image will be compared against acquired images to detect Area Defects.
- Mask Image: Represents the location and value of Masked Pixels, and the location of Masked Edge Segments. The Mask Image does not include areas of the image excluded by the shape of an EditCompositeRegion function, or other non-rectangular shapes.
- Residual Image: Produced by comparing the acquired image against the Model Image and Mask Image. This image is generated to detect Area Defects.