# CLensRimVision: A Novel Computer Vision Algorithm for Detecting Rim Defects in Contact Lenses
## 4 Methodology
### Defect Detection
#### 4.4.2 Correction of Criteria
Initially, it overlays a red mask onto the image to enhance visualization and to help in assessing how well the algorithm is performing. Simultaneously, it employs a specific image processing technique, which we will delve into in the next section. In terms of performance assessment, the algorithm relies on these enhanced images to calculate evaluation metrics. This assessment involves comparing the algorithm's results to a labeled dataset, as we will discuss in detail in the following sections focusing on evaluation metrics and dataset information. ```
Input (1) New_AVG as Window_new_local_AVG or Window_local_AVG incase using with or without correction of criterion function respectively. (2) Shrink_criterion is a parameter from either \"Shrink thickness\" or \"Shrink area\". (3) Extended_criterion is a parameter from wither \"Extended thickness\" or \"Extended area\". (4) Window_value is a thickness or area value of a certain window. Output (1) List Boolean of the defect as Bools_results Begin 1.//defect detection 2.Bools_results = [] 3.For (window=0, window= Criteria_based_list.length, window=window+1) then//line 12 in Algorithm 1 4.//window sliding: return AVG, SD, Criteria_based_list 5.//correction of criterion: return Window_new_local_AVG 6.//start defect detection 7.New_AVG = Window_new_local_AVG//shorten the variable name 8.If (New_AVG - Shrink_criterion < Criteria_based_list[window] < New_AVG + Extended_criterion) 9.Bools_results.append(True) 10.Else Bools_results.append(False) 11.Return Bools_results
```

**Algorithm 3** Acceptable range calculation for defect detection

### Image Processing for Visualization

In this step, the reverse function of the polar coordinate transformation is employed. The predicted circle coordinates (x, y) and radius (r) obtained from the circle detection are used as input for this reverse function. The polar transformation equation is a reversible function used to convert the linear image back into a circular image, as illustrated in Figure 10. In the process of defect detection, the algorithm will mask the red contour on the defect following the window size in which the contour represents a rectangle size in the image before reversing polar transformation. In the output from the defect detection step, the image region containing defects is highlighted in red. The algorithm utilizes a color space method for image processing to extract the red contours, convert them into bounding areas, and present the result, as depicted in Figure 10.

## 5 Results

In the previous section, we proposed a novel algorithm that can perform defect detection at the rim area of contact lens bycalculating criteria by either thickness-based or area-based. In this section, we present the results of our algorithm's performance for different configurations and criteria. Table 2 summarizes the outcomes for both the \"thickness-based\" and \"area-based\" approaches. These results demonstrate the influence of varying shrink and extended thickness criteria, the number of images above and below a specified pixel size of split images, and the factor correction applied to the criteria. The values of the parameter that we set in each trial of the experiment were chosen intentionally. We carefully selected the values for each parameter through a series of experimental trials. For the shrink/extended criteria, we opted for values that were closely aligned with the original, introducing only slight variations to explore the optimal parameter settings that

Figure 10: Image processing for visualization result. would be the most effective acceptable range to detect defects in the contact lens. When it came to the \"Number of windows above/below\" and \"Factor correction of criterion\", both were set as fixed parameters. The \"Number of windows above\" was established as 20 because this configuration involves 20 windows above and 20 windows below the window currently focused on, totaling 40 windows. This exceeds the threshold of 30, as stipulated by the central limit theorem [34].