# ViDiELAnomalyDetect

The ViDiELAnomalyDetect 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. automatically recognizes defects, debris, and other faults, allowing you to identify unknown or unanticipated defects on your inspected parts. This tool requires initial training on a sample image set, with manual classification of the images as OK or NG. Based on this training, the tool inspects new acquisitions to determine deviations from the OK training set, and predicts the acquisitions accordingly.

To use the ViDiELAnomalyDetect function:

1. Prepare your training samples:

   - If you are training the function with saved images, load your sample image set into the Filmstrip, and load the first image in your set into the Spreadsheet.

   - If you are using live acquisitions for training, prepare the inspection object for the first training acquisition Acquisition is the process or result of the vision system acquiring a new image..

   - Make sure that the ViDiELAnomalyDetect function is using fixtured images from an upstream fixturing tool as input images to ensure that all inspections are performed using the same perspective. To change the input image of the ViDiELAnomalyDetect function, double-click the Image parameter in the property sheet and select the output cell of the fixturing tool.

2. Drag and drop the ViDiELAnomalyDetect tool into the Spreadsheet.

   The property sheet pops up:

   Element | Description
   --- | ---
   1 | Image display
   2 | Sample labeling controls
   3 | Tool predictions
   4 | Function property list
   5 | Sample images labeled for training
   6 | Tool settings

3. You can find the property list for the ViDiELAnomalyDetect function in the top right section of the property sheet. Set up the Region of Interest using one of the following methods:

   - Double-click the Region parameter and adjust the ROI box on the acquisition display.

   - Expand the Region parameter and define the box parameters manually.

4. Depending on the size of the anomalies you want the tool to find, you can also adjust the feature size and anomaly threshold:

   - You can adjust the feature size using the Feature Size (px) slider in the tool settings next to the image display, or click Optimize for automatic feature size settings.

     Note: Larger feature size settings decrease the resolution of the image for faster processing, and smaller feature size settings provide better accuracy at the cost of speed.

   - By default, the tool automatically sets the anomaly threshold based on the detection settings. The Auto-Threshold Options dropdown in the tool settings next to the image display allows you to set the automatic anomaly threshold to the following options:

     - Prioritize OK Detection sets the automatic anomaly threshold to reduce the number of OK results that are falsely classified as NG.

     - Balanced Detection sets the automatic anomaly threshold to minimize undetected anomalies while avoiding false positives.

     - Prioritize NG Detection sets the automatic anomaly threshold to reduce the number of NG results that are falsely classified as OK.

     Alternatively, you can disable the Autoset Anomaly Threshold setting in the tool settings next to the image display, which enables the Anomaly Threshold property in the property list. The Anomaly Threshold property allows you to manually specify the anomaly score above which an inspection produces a NG result.

5. You can also enable or disable a heat map overlay using the Heat Map toggle in the tool settings next to the image display.

6. Train the ViDiELAnomalyDetect function:

   1. Label the first image from your sample image set as OK or NG by clicking on the OK or NG button in the result controls next to the image display.

   2. Load the next image in your sample set:

      - If you are training the function with live acquisitions from the vision system, click the Next Image button to send a manual trigger.

      - If you are training the function with images loaded from the Filmstrip, double-click the next image in the Filmstrip to load it.

   3. Label the next image, and repeat until you have labeled at least two OK images and one NG image.

   4. To review your training images, click on the Edit button next to Sample Image in the bottom right section of the property sheet. The sample image view allows you to delete or relabel any images you have added to the training set.

7. Once you have trained the ViDiELAnomalyDetect function, the tool displays a detected anomaly score and a predicted class of OK or NG next to the image display.

Inputs

Parameter | Description
--- | ---
Image | Reference to a cell containing an Image structure. The default value is $A$1.
Fixture A fixture is a coordinate location on the image that keeps the tool in the place determined by the fixture. | Fixture origin (X, Y, Theta). Offsets from the image origin. The default setting is (0,0,0), the top leftmost corner of the image.
X | The X-offset, in image coordinates.
Y | The Y-offset, in image coordinates.
Theta | The rotation from the image X-axis, in the image coordinate system. (+/-360 degrees clockwise)
Region | Region of Interest (X, Y, Width, Height, Angle).
X | The X-offset of the origin, in fixture coordinates.
Y | The Y-offset of the origin, in fixture coordinates.
Width | The dimension along the X-axis of the region.
Height | The dimension along the Y-axis of the region.
Angle | The orientation, in fixture coordinates.
Curve | The angular deviation between the x-axis and the opposing boundary line of the region.
Anomaly Threshold | Specifies the threshold above which an anomaly score produces a NG label. Note: This parameter is disabled by default. To enable the parameter, disable the Autoset Anomaly Threshold setting in the tool settings next to the image display.
Show | Select the type of graphic to overlay on the image.
0 = hide all (default) | All graphics are hidden, except when the cell containing the ViDiELAnomalyDetect function is highlighted in the Spreadsheet.
1 = result graphics only | Only the result graphics are displayed on the image.
2 = input and result graphics | Both the input graphics and result graphics are displayed on the image.

Outputs

The ViDiELAnomalyDetect function produces the following output cells in Spreadsheet:

Output | Description
--- | ---
Label | The label applied to the result.
Anomaly Score | The anomaly score of the result.
Output Mask | The output mask showing the anomalies on the result.