# CLensRimVision: A Novel Computer Vision Algorithm for Detecting Rim Defects in Contact Lenses
## 4 Methodology
### Defect Detection
#### 4.4.2 Correction of Criteria
We conducted a comparative test between the results of using the window-sliding technique and tnot using it, as presented in Figure 13a,b, respectively. The testing results are based on the area-based approach, with both results having an extended and shrink area ratio set to 0.3 and a split image size of 10 pixels. As a result, the image in Figure 13a can detect fewer defects than the image in Figure 13b. Most of the detections in Figure 13b do not represent actual defects; instead, they are normal curves without defects. However, their values may fall outside the acceptable range during the defect detection stage. We can conclude that Figure 13a yields more precise results in defect detection in this case, aided by the window-sliding technique. Figure 13: A comparison between the results of using or not using correction criterion function in the algorithm based on the area-based algorithm. (a) A result from the algorithm using window-sliding method; (b) A result from the algorithm without window-sliding method. ### Effectiveness of Correction of Criteria Function

The correction of the criterion function is used to eliminate spike values from the local regions of interest in the window-sliding method. These spikes can potentially occur due to defects in the contact lens. However, when finding the average value of the local area, we do not want to include these spikes, as they may lead to an inaccurate average value for either the thickness (in the case of the thickness-based approach) or area (in the case of the area-based approach) within the local region. The purpose of this function is to remove outliers from the average criterion value in the local region that could interfere with the overall calculated average value. The correction of the criterion function employs statistical mathematics to limit the range of the average local value, as defined in Equation (6), in which we manually set the proportion as factor F. Assuming that there are extended spikes resulting from defects, mathematically, the average will be higher than in cases without any defects. Conversely, if a local region has cuts or shrinkage defects in a linear shape within the region of interest, the average value will be lower than usual. In Figure 13(a), there is a demonstration of a contact lens image that has been tested for defect detection using the CLensRimVision algorithm with the correction criteria function. In contrast, Figure 13(b) shows the result without using the correction criteria function. The results reveal that the example image using the correction criteria has fewer detections compared to the other image without the correction criteria. This is because it detects only the defects that appear on the rim of the contact lens. Figure 13(b) has some detections that are false positives for defects because they may have higher or lower average values than they should. Consequently, some values that should not be detected are also identified as defects on the rim. ### Characteristics of Criterion-Based Methods

In the CLenRimVision algorithm, there are two criterion-based methods available: the thickness-based and the area-based approaches. Both methods serve the same purpose, which is to count the number of black pixels within the region of interest during the window-sliding process. In this section, we aim to highlight the characteristics of each approach, as they may be suitable for different applications and objectives. Each approach comes with its own set of required parameters for the shrink value and extended value used in the calculation of the acceptable range. These parameters offer the flexibility to meet the standards and specific industry needs associated with different contact lens grades, such as economy-priced beauty contact lenses, premium contact lenses, and myopia contact lenses. When compared to physical contact lenses, the thickness-based method is more intuitive to configure within the algorithm.