DetectFlaw

The DetectFlaw function is used to identify flaws by comparing the trained data contained in a either a valid TrainFlawModel data structure returned by a TrainFlawModel function, or a FlexFlawModel data structure returned by a FlexFlawModel function, and the currently acquired image. The DetectFlaw function is capable of identifying the following three types of flaws: Area Defects, Missing Edge Defects and/or Extra Edge Defects. For more information about TrainFlawModel, see TrainFlawModel. For more information about FlexFlawModel, see FlexFlawModel.

Area inspections verify whether or not there are defects such as scratches or stains on the surface of the object/part. Edge inspections verify whether or not 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.

Tip:
  • One or more DetectFlaw functions may be referenced to a single TrainFlawModel function, which allows each DetectFlaw function to inspect different portions of the object/part using different settings, if necessary.
  • Additional image processing may be performed on the DetectFlaw output image when the Display Image parameter is set to either Edge Image, Model Image, Mask Image or Residual Image. For example, additional blob image analysis could be performed by setting an ExtractBlobs function's Image parameter to the use the Residual Image of the DetectFlaw function as an input.
  • To reduce the function's execution time, set the function's Image Resolution parameter to Medium or Coarse, which down-samples the image and decreases the function's sensitivity to image noise and very small variations.

DetectFlaw Inputs

General Tab

Syntax: DetectFlaw(Flaw Model Reference,Inspection Region.X,Inspection Region.Y,Inspection Region.High,Inspection Region.Wide,Inspection Region.Angle,Inspection Region.Curve,External Inspection Region or Path,Image Resolution,Mask Image Controls.Add Residual,Mask Image Controls.Default Mask,Defect Parameters.Minimum Contrast,Defect Parameters.Normalize,Defect Parameters.Area Defect Type,Defect Parameters.Minimum Area Defect Size,Defect Parameters.Edge Defect Type,Defect Parameters.Minimum Edge Defect Size,Draw Edge Markings,Draw Flaw Markings,Display Image,Show )

Parameter Description

Flaw Model Reference

Specifies a reference to a spreadsheet cell that contains either a valid TrainFlawModel data structure returned by a TrainFlawModel function, or a FlexFlawModel data structure returned by a FlexFlawModel function.

Inspection Region

Specifies the region, also known as the Region of Interest (ROI), of the image that undergoes image analysis; creates a rectangular image region that can be transformed and rotated. With this parameter selected, by pressing the Maximize Region button on the property sheet's toolbar, the region will automatically be stretched to cover the entire image.

Note:
  • The Inspection Region parameter must be defined within the bounds of the image; otherwise, the function will return #ERR.
  • The Inspection Region will automatically be fixtured to the same input fixture specified in the referenced TrainFlawModel function. If the fixture reference is invalid, the fixture will default to 0,0,0.

X

The x-offset of the origin, in fixture coordinates.

Y

The y-offset of the origin, in fixture coordinates.

High

The dimension along the region's x-axis.

Wide

The dimension along the region's y-axis.

Angle

The orientation, in fixture coordinates.

Curve

The angular deviation between the region's x-axis and the opposing boundary line.

External Inspection Region or Path

Specifies a reference to a spreadsheet cell that contains a Controls function. When this parameter is used, the TrainFlawModel tool ignores the Region and Fixture settings and inspects the image area specified by the referenced region.

Note: If this parameter has been set as a reference to an external region or path, to use the function's internal Region, this parameter must be manually set to zero by entering the value 0 in place of the cell reference. Otherwise, the function will continue to reference the external region or path.

Image Resolution

Specifies an image processing resolution for the function, which allows the function to down-sample the inspection image. This parameter specifies the resolution used to perform flaw detection, as well as the resolution of the output image and markings on the image.

Tip: Use the Medium or Coarse settings to reduce the execution time of the function, or to decrease the function's sensitivity to image noise and very small variations.
Note: If the Model Reference parameter is referencing a FlexFlawModel data structure returned by a FlexFlawModel function, this parameter will be disabled and the Image Resolution parameter settings of the FlexFlawModel function will be used instead.

1 = Fine (default)

Specifies that full image resolution will be utilized.

2 = Medium

Specifies that half image resolution will be utilized.

3 = Coarse

Specifies that quarter image resolution will be utilized.

Mask Image Controls

Specifies an external reference to a Button or Event function to control how the function processes the Mask Image. These references provide the ability to dynamically adjust the mask during run-time to ignore certain flaws.

Add Residual

Specifies a reference to a Button or Event function to add the current residual image to the Mask Image.

Default Mask

Specifies a reference to a Button or Event function that sets the Mask Image to its initially trained state, by regenerating the mask data from the Model Image.

Defect Parameters

Specifies the limits for determining area and/or edge flaws. Area flaws are measured by deviations of the pixel greyscale value, and typically include defects such as blemishes or discolorations. Edge flaws are measured by the presence/absence of edge features, and typically include defects such as scratches, tears or extra features.

Note: When applying the DetectFlaw function, if the tolerances for the Defect Parameters are narrow (i.e. ≤ 15 pixels, for instance), and the image encounters minor variations in image noise, the options Ignore Defect and Add Residual may not account for the variations. In these situations, attempt to broaden the tolerances for the Defect Parameters before applying the Ignore Defect or Add Residual options.

Minimum Contrast

Specifies the minimum contrast (1 to 255; default = 25) transition value to be considered as an edge or an area defect.

Normalize

Specifies whether or not the normalization of intensity levels in the residual image will be performed prior to inspecting the region for area defects.

0 = Off (default)

Specifies that the function will not perform normalization of intensity levels prior to inspecting for area defects.

1 = On

Specifies that the function will perform normalization of intensity levels prior to inspecting for area defects.

Area Defect Type

Specifies the type of area defects to identify. When enabled, the function will identify blobs of pixels in the residual image that exceed the specified Minimum Contrast and Minimum Area Defect Size values.

0 = None

Disables area defect detection.

1 = Both (default)

The function will identify defects that are caused by pixels in the currently acquired image that are either brighter or darker than those in the trained model.

2 = Light Defects

The function will only identify defects that are caused by pixels in the currently acquired image that are brighter than those in the trained model.

3 = Dark Defects

The function will only identify defects that are caused by pixels in the currently acquired image that are darker than those in the trained model.
Minimum Area Defect Size

Specifies the minimum area defect size (2 to 400000; default = 30), in pixels; an area below this value is not considered a defect.

Edge Defect Type

Specifies the type of edge defects to identify.

0 = None

The function will not identify edge defects.

1 = Both The function will verify the presence/absence of both Missing Edges and Extra Edges.

2 = Missing Edges (default)

The function will verify that all of the previously trained edges in the model are present in the currently acquired image. Missing edges that exceed the specified Minimum Edge Defect Size value will be classified as a flaw.

3 = Extra Edges The function will verify that there are not additional edges present in the currently acquired image that were not in the trained model. Extra edges that exceed the specified Minimum Edge Defect Size value will be classified as a flaw.
Minimum Edge Defect Size Specifies the minimum length (2 to 1000; default = 5) of an edge to classify it as a missing and/or extra edge; detected edges shorter than this setting are not classified as defects.
Draw Edge Markings

Specifies whether or not the function will draw the detected edge marks, in green, on the image. The output markings indicate which pixels align with pixels in the trained Model Image. Pixels in the acquired image which coincide with a trained edge segment in the trained Model Image will be drawn in green. Pixels which fall outside of tolerances and are classified as either edge or area defects are drawn in red, and a red bounding box is placed around them.

0 = Off (default)

Specifies that the function will not draw the edge marks on the image.

1 = On

Specifies that the function will draw the edge mark on the image.

Draw Flaw Markings

Specifies whether or not the function will draw the detected flaw marks, in red, on the image. The output markings indicate which pixels align with pixels in the trained Model Image. Pixels in the acquired image which coincide with a trained edge segment in the trained Model Image will be drawn in green. Pixels which fall outside of tolerances and are classified as either edge or area defects are drawn in red, and a red bounding box is placed around them.

0 = Off (default)

Specifies that the function will not draw the detected flaw marks, in red, on the image.

1 = On

Specifies that the function will draw the detected flaw marks, in red, on the image.

Display Image

Specifies the type of output the function will generate.

0 = Live Image (default)

The function will generate the currently acquired image as the output image.

1 = Edge Image

The function will generate the edge model from the currently acquired image as the output image. This option is only available if the Edge Defect Type parameter is set to Missing Edges, Extra Edges or Both, or the function is referencing a FlexFlawModel data structure returned by a FlexFlawModel function in the Model Reference parameter.

2 = Model Image The function will generate the trained model image, after being transformed based on fixture and scale, and, optionally, Flex algorithms.
3 = Mask Image The function will generate the current mask image, after being transformed based on fixture and scale, and, optionally, Flex algorithms.
4 = Residual Image

The function will generate the residual image based on the flaw detection analysis.

Note: If the residual image is being used as an output image, Area Defects must be enabled. Otherwise, edge defects will still be drawn, but the output image will not be generated and an error message will be displayed.

Show

Specifies the display mode for DetectFlaw graphical overlays on top of the image. The output markings indicate which pixels align with pixels in the trained Model Image.

Note: When the DetectFlaw property sheet is open, all of the markings will be drawn on the image, if the Draw Edge Markings and Draw Flaw Markings parameters are enabled.
0 = hide all (default)

All graphics will be hidden, except when the cell containing the DetectFlaw function is highlighted in the spreadsheet.

1 = result graphics only

The enabled markings, defects and input region will be displayed at all times.

2 = show all: input and result graphics

Both the input region, detected defects, and detected edges will be displayed at all times.

Note: The Draw Edge Markings and Draw Flaw Markings parameters must be enabled to display the detected defects and edges.

Edit Mask Tab

Mask Image Editing Controls

The Mask Image Editing controls provide a means to manipulate the mask image saved in the referenced TrainFlawModel data structure. While the Edit Mask tab is selected, the image will be displayed, and if the Edge Defect Type parameter is enabled, masked edges will be marked, and if the Area Defect Type parameter is enabled, the mask image will be displayed.

Note:
  • Adjusting the Mask Image will affect any other DetectFlaw functions that reference the same TrainFlawModel function which contains the Mask Image.
  • When applying the DetectFlaw function, if the tolerances for the Defect Parameters are narrow (i.e. ≤ 15 pixels, for instance), and the image encounters minor variations in image noise, the options Ignore Defect and Add Residual may not account for the variations. In these situations, attempt to broaden the tolerances for the Defect Parameters before applying the Ignore Defect or Add Residual options.
Add Residual Image Specifies that the residual image and residual edges will be added to the mask. This setting has the effect of changing the defects identified in the image into non-defects.
Expand Mask

Specifies that the area of the pixels in the mask are expanded.

Note: Area Defect Types must be enabled to use this option.
Shrink Mask  

Specifies that the area of the pixels in the mask are reduced.

Note: Area Defect Types must be enabled to use this option.
Remove Mask Specifies that all of the mask data is removed.
Default Mask Specifies that the Mask Image is reset to its initially trained state, by regenerating the mask data from the Model Image.

Defect List Tab

Defect List Table

The Defect List provides a sortable table of the detected flaw(s). Selecting a flaw in the list will highlight it in the image, and also enables the Ignore Defect button; multiple flaws may be selected by using either the CTRL or SHIFT keys while selecting defects in the list.

Note: When applying the DetectFlaw function, if the tolerances for the Defect Parameters are narrow (i.e. ≤ 15 pixels, for instance), and the image encounters minor variations in image noise, the options Ignore Defect and Add Residual may not account for the variations. In these situations, attempt to broaden the tolerances for the Defect Parameters before applying the Ignore Defect or Add Residual options.
Number Specifies the numeric order of the detected flaws, from 1 to N.
Type Specifies the type of flaw: Extra Edge, Missing Edge or Area.
Size Specifies the size, in pixels, of the flaw.
Contrast Specifies the contrast of the flaw.
Row Specifies the row coordinate of the bounding box surrounding the flaw.
Column Specifies the column coordinate of the bounding box surrounding the flaw.
Height Specifies the height value of the bounding box surrounding the flaw.
Width Specifies the width value of the bounding box surrounding the flaw.
Ignore Defect Button Specifies that the selected flaw(s) will be added to the Mask Image, no longer reported as a flaw and removed from the list. A flaw must be selected to enable the button.

DetectFlaw Outputs

Returns

A DetectFlaw data structure containing the detected flaws, or #ERR if any of the input parameters are invalid.

Note: The DetectFlaw data structure may be used as an Image input for other Vision Tools. For more information, see Vision Tools Functions.

Results

When DetectFlaw is initially inserted into a cell, a results table is created in the spreadsheet.

 

DetectFlaw Vision Data Access Functions

The following Vision Data Access functions are automatically inserted into the spreadsheet to create the DetectFlaw data structure result table. For more information on Vision Data Access functions, see Flaw Detection.

Spreadsheet Name

Function Name

Description
Summary Total Count GetTotalFlawCount(DetectFlaw, Type) Returns the total number of detected flaws, regardless of type.
Total Flaw Size GetTotalFlawSize(DetectFlaw, Type) Returns the total number of pixels that are classified as flaws.
Count
Area GetTotalFlawCount(DetectFlaw, Type) Returns the total number of detected area flaws.
Missing Edges GetTotalFlawCount(DetectFlaw, Type) Returns the total number of detected missing edge flaws.
Extra Edges GetTotalFlawCount(DetectFlaw, Type) Returns the total number of detected extra edge flaws.
Flaw Size
Area GetTotalFlawSize(DetectFlaw, Type) Returns the total number of pixels that are classified as area flaws.
Missing Edges GetTotalFlawSize(DetectFlaw, Type) Returns the total number of pixels that are classified as missing edge flaws.
Extra Edges GetTotalFlawSize(DetectFlaw, Type) Returns the total number of pixels that are classified as extra edge pixels.

Flaw Type

Note:  For each of the Flaw Types (Area, Missing Edge and Extra Edge) the first five detected flaws are displayed.
Size GetFlawSize(DetectFlaw, Type, Index) Returns the size, in pixels, of the flaw.
Contrast GetFlawContrast(DetectFlaw, Type, Index) Returns the contrast of the flaw.
Row GetFlawRow(DetectFlaw, Type, Index) Returns the row coordinate of the bounding box surrounding the flaw.
Col GetFlawCol(DetectFlaw, Type, Index) Returns the column coordinate of the bounding box surrounding the flaw.
High GetFlawHigh(DetectFlaw, Type, Index) Returns height value of the bounding box surrounding the flaw.
Wide GetFlawWide(DetectFlaw, Type, Index) Returns the width value of the bounding box surrounding the flaw.