# CLensRimVision: A Novel Computer Vision Algorithm for Detecting Rim Defects in Contact Lenses
## 4 Methodology  
This chapter explains the concept of CLensRimVision algorithm to detect defects on the edge of the outer circle of the contact lens. ClensRimVision algorithm comprises two main components: the offline process and the online process. The term 'offline process' refers to the setting of parameters which must be fully established prior to implementation or production. We use 'offline' to emphasize that these preparations are essential and must be completed beforehand. Conversely, the 'online process' pertains to the actual implementation of the algorithm, specifically for defect detection on a production line. The workflow of ClensRimVision algorithm is as shown in Figure 4. In this proposed algorithm, we integrate both basic image processing methods and our designed methods within the overall workflow. The description of basic image processing is provided in Section 4.1, Section 4.2, Section 4.3, Sections 4.4 and 4.5. However, the sequence for connecting each method is determined and arranged by us. This arrangement has been proven to guarantee the desired output results and performance of our experiments. The innovative part that can significantly increase our chance to fulfill our objective, as explained in Section 4.4, constitutes the core idea of this research paper. The sequencing of the system workflow is also a significant aspect contributing to the innovation of this research. Each step in the workflow plays a crucial role in enhancing the results of the preceding part, as it serves as the input for the subsequent stage. In the offline process, various parameters are carefully configured to optimize the performance of the defect detection algorithm. During implementation, images of the contact lens may be captured under different settings, such as various methods of capture, lighting conditions, distances, and more. Therefore, proposing an algorithm that can dynamically adjust parameters according to different settings is essential. This entails setting parameters for three key aspects: image preprocessing, circle detection, and defect detection, as shown in Table 1. These parameters are predetermined and serve as the foundation for the defect detection system. In the online process, the algorithm utilizes the configured parameters to analyze and detect defects on the edges of contact lenses. This is achieved through the application of image processing procedures and the proposed algorithms. The online process takes input images or a combination of computer vision modules as input and performs defect detection based on the configured parameters from the offline process. Furthermore, the algorithm's workflow comprises five main execution steps as follows:  
1. Image Preprocessing: This step is responsible for adjusting and preprocessing the input contact lens image to convert it into a contour image, highlighting the rich details and essential components within the image. In Figure 4, labelled \"Input\" shows the input image of ClensRimVision algorithm, and labelled \"1\" shows the output of the Image Preprocessing step. 2. Circle Detection: This step focuses on detecting the area and coordinates of the circular contact lens within the input image. The red circle in Figure 4, labelled \"2\" shows output of Circle Detection step.