# FlexFlawModel

The FlexFlawModel function Functions are tools that are available in Spreadsheet for processing and analyzing acquisitions or other results. You can add functions to your Spreadsheet job to create tool chains and produce results for specific applications. is used to construct optional Flex algorithms, which help compensate for acceptable process variations in the TrainFlawModel function, allowing theDetectFlaw function to better classify flaws. The FlexFlawModel function measures the displacement within theTrainFlawModel or Mask function's Region, by comparing the trained Edge Model against the Edge Model in the currently acquired image.

## FlexFlawModel Overview

The FlexFlawModel function operates within the ROI specified by the referenced TrainFlawModel function. During inspection, the function will translate, rotate and scale the trained Edge Model to the current location and orientation of the part, based on the fixture A fixture is a coordinate location on the image that keeps the tool in the place determined by the fixture. and scale values in the referenced TrainFlawModel function. The FlexFlawModel function will then extract the edges within the ROI, at the specified Image Resolution value. These extracted edges will be compared against the trained Edge Model. The function then calculates an initial Match Score, and if this first score is too low, the function will return #ERR. Provided the Match Score is high enough, the function executes the Flex algorithm, based on the Flex Recipe values. Afterward, the function calculates a final Flex Score.

Building the Flex algorithms, by adjusting the input parameters, allows the model to "stretch" to compensate for acceptable variations that would otherwise be classified as flaws. This stretching also helps the model more closely resemble the part in the currently acquired image. Flex may be applied to align the part prior to running the DetectFlaw function to reduce false rejects.

The Flex algorithms help compensate for the following:

- Positional errors, such as slight movements from image to image.
- Lens or perspective distortion.
- Acceptable part variations, such as slight differences in shape or surface values.
- Pixel lengthening, such as that associated with line scan images.
- The part's scale changes in the image.

## FlexFlawModelInputs

Parameter | Description
TrainFlawModel | Specifies a reference to a spreadsheet cell that contains a valid TrainFlawModel data structure returned by a TrainFlawModel function.
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.
0 = Fine (default) | Specifies that full image resolution will be utilized.
1 = Medium | Specifies that half image resolution will be utilized.
2 = Coarse | Specifies that quarter image resolution will be utilized.
Minimum Edge Strength | Specifies the minimum required greyscale intensity transition (5 to 255; default = 20) to extract edge features from the image.
Minimum Match Score | Specifies the initial minimum match score (10 to 100; default = 30) to initiate the use of the Flex Parameters. If the initial match score is less than this value, then the Flex Parameters will not process and the function will result in #ERR.
Flex Parameters | Specifies the limits to the flex type and the amount of flex which can be tolerated.
Flex Recipe | Specifies a set of read-only pre-configured settings, which provide a suggested set of values for different applications.
0 = Default | Flex Grid Size = 8x8; Allow Enclosed Segment Flex = OFF; Enclosed Segment Flex = 20; Allow Line Segment Flex = ON; Line Segment Flex = 10; Line Segment Maximum Line Size = 15; Allow Pixel Flex = ON; Pixel Flex = 1.
1 = Large Flex | Flex Grid Size = 4x4; Allow Enclosed Segment Flex = ON; Enclosed Segment Flex = 40; Allow Line Segment Flex = ON; Line Segment Flex = 20; Line Segment Maximum Line Size = 8; Allow Pixel Flex = ON; Pixel Flex = 10. Tip: Large Flex is best suited to applications where there is significant non-linear distortion.
2 = Print Growth | Flex Grid Size = 4x4; Allow Enclosed Segment Flex = ON; Enclosed Segment Flex = 30; Allow Line Segment Flex = ON; Line Segment Flex = 1; Line Segment Maximum Line Size = 40; Allow Pixel Flex = ON; Pixel Flex = 1. Tip: Print Growth is best suited to applications to verify the quality of printed characters and the function must adjust to growth in the characters.
3 = Mouse Bite | Flex Grid Size = 8x8; Allow Enclosed Segment Flex = ON; Enclosed Segment Flex = 5; Allow Line Segment Flex = ON; Line Segment Flex = 5; Line Segment Maximum Line Size = 10; Allow Pixel Flex = ON; Pixel Flex = 1. Tip: Mouse Bite is best suited to applications that are edge boundary-based and the flaw sizes are very small.
4 = Fine Detail | Flex Grid Size = 2x2; Allow Enclosed Segment Flex = ON; Enclosed Segment Flex = 10; Allow Line Segment Flex = ON; Line Segment Flex = 3; Line Segment Maximum Line Size = 15; Allow Pixel Flex = ON; Pixel Flex = 1. Tip: Fine Detail is best suited to applications where there is significant non-linear distortion for detecting small flaws. This option is more time consuming.
98 = Custom | Allows for custom creation of Flex Recipe settings, by manually entering different values in the Flex Parameters. The initial values will be based on the previously selected recipe's default values. Note: If a cell reference has been created to control the Flex Recipe selection, and the property sheet for the function is opened and changes are made to the Flex Recipe parameter, the function will overwrite the command from the cell reference.
99 = No Flex | Flex Grid Size = 2 x 2; Allow Enclosed Segment Flex = OFF; Enclosed Segment Flex = 1; Allow Line Segment Flex = OFF; Line Segment Flex = 1; Line Segment Maximum Line Size = 3; Allow Pixel Flex = OFF; Pixel Flex = 1. Note: The No Flex setting specifies that the function will use the minimum allowed settings to compute flex. To apply no flex whatsoever, the FlexFlawModel function itself must be disabled.
Flex Grid Size | Specifies a granularity setting that is applied to the Model Image and Mask Image when corrections for flex are utilized. The higher granularity setting more accurately handles non-linear distortion, but will consume more memory.
0 = 2x2 | Specifies the highest granularity setting.
1 = 4x4 | Specifies the second highest granularity setting.
2 = 8x8 (default) | Specifies the third highest granularity setting.
3 = 16x16 | Specifies the lowest granularity setting.
Allow Enclosed Segment Flex | Specifies whether or not the function will tolerate the displacement of enclosed segments.
1 = ON | The function will tolerate the displacement of enclosed segments.
0 = OFF (default) | The function will not tolerate the displacement of enclosed segments.
Enclosed Segment Flex | Specifies the maximum amount of displacement (1 to 40; default = 20) that will be tolerated from the center of the enclosed segments.
Allow Line Segment Flex | Specifies whether or not the function will tolerate the displacement of a portion of an edge.
1 = ON (default) | The function will tolerate the displacement of a portion of an edge.
0 = OFF | The function will not tolerate the displacement of a portion of an edge.
Line Segment Flex | Specifies the maximum amount of line segment displacement (1 to 20; default = 10) that will be tolerated for edge segments.
Line Segment Maximum Line Size | Specifies the maximum length (3 to 500; default = 15) in which an edge may be divided into.
Allow Pixel Flex | Specifies whether or not flex will be calculated for each edge pixel.
1 = ON (default) | The function will calculate flex for each edge pixel.
0 = OFF | The function will not calculate flex for each edge pixel.
Pixel Flex | Specifies the maximum amount of displacement (1 to 10; default = 1) a pixel may undergo.
Draw Options | Specifies which results the function will draw on the image.
0 = Edge Markings (default) | Specifies that the function will draw the edge match results, between the current edge model and the edge model after the flex algorithm has been applied.
1 = Edge Displacement | Specifies that the function will draw the results to indicate how the model image has been modified via the flex algorithms to match the currently acquired image.
2 = Grid Displacement | Specifies that the function will first internally divide the image into a grid to indicate the quantity and direction that the pixels within a section of the grid were modified via the flex algorithms to match the currently acquired image.
3 = None | Specifies that no drawing will be performed.
Display Image | Specifies the type of output image the function will generate.
0 = Live Image (default) | Specifies that the function will display the currently acquired image.
1 = Edge Image | Specifies that the function will display the edge model generated from the currently acquired image.
Show | Specifies the display mode for FlexFlawModel graphical overlays on top of the image. Pixels that match those in the trained model will be colored green; pixels that do not match will be colored yellow; pixels that are missing from the Mask Image will be colored blue; extra pixels in the Mask Image will be colored dark magenta; extra edge defects will be colored magenta; and missing edge and area defect pixels will be colored in red.
0 = hide all (default) | All graphics will be hidden, except when the cell containing the FlexFlawModel function is highlighted in the spreadsheet.
1 = result graphics only | The selections specified in the Draw Options and Display Image and the inspection region of the referenced TrainFlawModel will be displayed at all times.
2 = show all: input and result graphics | Both the input region, the selections specified in the Draw Options and Display Image and the inspection region of the referenced TrainFlawModel will be displayed at all times.

## FlexFlawModel Outputs

Returns | A FlexFlawModel data structure containing the Flex algorithm modified model data, or #ERR if any of the input parameters are invalid.
Results | When FlexFlawModel is initially inserted into a cell, to the right of the data structure, two cells are automatically populated with the FlawDetection Vision Data Access functions: GetMatchScore and GetFlexScore. GetMatchScore returns a value indicating the edge match score prior to the Flex algorithm being applied, and GetFlexScore returns a value indicating the edge score after the Flex algorithm has been applied.