# Inspect Textures and Textiles with Red Analyze

Inspecting textures and textiles is a typical example of an aesthetic inspection. Textures and textiles can have many different types of defects, and often have an element of random variation as well, either from material properties such as brush strokes or weaves in fabric, or from camera alignment such as shearing or rotation. The difficulty of inspecting textures and textiles comes from accepting normal variations while still detecting small defects.

While the Unsupervised type Red Analyze tool is able to find anomalies in complex surfaces and textures, it requires that the anomalies are visually noticeable enough that they can be separated from the background texture. If the Unsupervised type is not responding to certain anomalies or defects as expected, you need to switch to Legacy type.

## Tutorial Objectives

- Understanding the difference between the Legacy, Unsupervised, and the Standard types.

- Labeling images as good or bad.
- Introducing the database statistics sidebar.
- Understanding the role of the Feature Size and Border Type parameters.
- Using the Perturbation parameters to improve performance.

## Legacy Tutorial Procedure

1. Add the images for the Textures tutorial.
2. Add a Red Analyze tool. The tool is in Legacy Legacy mode by default.
3. Use the default ROI The Region of Interest (ROI) defines the area of operation for the tool. The ROI preserves the positions, angles, stretch and skew of the original image. size, and segment the images by clicking the Scissors icon.
4. Click Actions for 575 Views, and select Label Views in the dropdown menu. Label all of the images as Good.
5. Type bad in the Display field to sort for images that contain the word "bad" in their file name. Label those images as Bad.
6. Train the tool and review the results. Note that the performance is very poor, with the tool reporting nearly all the images as intermediary.
7. Switch the tool to Standard architecture.
8. In 20 of the "bad" images, label the defective areas with Regions.
9. Train the tool and review the results.
10. If necessary, label additional defective areas and retrain.

## Unsupervised Tutorial Procedure

1. Add the images for the Textiles tutorial.
2. Add a Red Analyze tool and switch this tool to Red Analyze Unsupervised.
3. Segment the images by clicking the Scissors icon.

4. Label the images as Good or Bad depending on whether or not they show an anomaly.

   Note: You can simplify the process by using the Label Views option in the View Browser.
5. Click the Train icon.
6. After training Training is the process that your tool, which is a neural network, is learning about the features (pixels) based on the labels you made. For example, a tool will learn the defect/normal pixels in each image based on the defect/normal labels you drew. The goal of the tool Training is learning enough to give the correct inspection results of whether an unseen image is defective or not. The key to training is to ensure that you include all possible variations within your training set, and that your images are accurately labeled. Training times vary by the application, tool setup and the GPU in the PC being used to train the network., review the results.
7. Expand the Database Overview sidebar on the right, and lower the green Threshold slider in the interactive Scores graph. You can see that the system tends to respond to the good images that are close to the border.
8. Right click on an image. In the context menu, select Edit Mask to open the Edit Mask toolbar, and use the Add Border option to add a mask to the border of the image.
9. In the Edit Mask toolbar, press the Apply button and apply the border mask to all the images in the database.
10. Reprocess the images and review the results.
11. There may still be a response in the strongly skewed region of the second bad image.
12. Expand the tool settings sidebar on the left, change the Shear and Aspect-Ratio to 5%, and retrain.
13. After training, these responses are reduced.