## 3 Preprocessing Process
### Finding Optimal Values  
Since the illumination or shadow area of an object in image data varies depending on location, time, and environmental factors, it is necessary to find the optimal value when applying contrast enhancement techniques. In this paper, OpenCV's CLAHE algorithm was applied to the preprocessing process as a contrast enhancement technique.  
In the optimal value extraction step, the optimal value for the 'contrast limit warning value', called cliplimit, and the 'additional brightness(\(\alpha\))' to be applied to improve the shadow area are obtained.  
The 'cliplimit' optimal value is obtained when the absolute brightness difference between the original image and the simple CLAHE-applied image is calculated. The variance of the pixel values is then calculated in the difference image, and this process is repeated for the cliplimit parameter range (0-255). The maximum variance value is designated as the optimal value.  
In the CLAHE algorithm, as the value of the 'cliplimit' parameter increases, more aggressive contrast enhancement occurs, and noise and artifacts may be excessively amplified. On the other hand, lower values may not improve contrast enough. The absolute difference in brightness between the two images indicates how much the pixel values have changed after the contrast enhancement. The variance calculation process is a measure of how spread out the pixel values are from the average value, with high variance values indicating a significant range of pixel values and low variance values indicating that the pixel values are close together. So, the value that produces the highest variance for cliplimit represents the optimal value because it represents the best balance between avoiding noise and overamplification.  
The formula for obtaining the optimal cliplimit value is as follows:  
\[\text{Optimal Cliplimit}=\text{max}\Big{(}\sum_{C=0}^{range}Var(\ |\ I_{L}- CLAHE(I,\ C)_{L}|)\Big{)} \tag{1}\]  
'\(C\)' is the cliplimit, the '_Var_' function is the variance, '\(L\)' is the brightness, and '\(I\)' is the original image.  
For the optimal value of 'additional brightness (\(\alpha\))', edge-detection is performed on the contrast enhancement image to which the cliplimit optimal value is applied, and the sharpness and variance in the sharpness are calculated. The maximum variance value obtained when this is repeated for the pixel range 0-255 is designated as the optimal value for '\(\alpha\)'.  
Edge-detection highlights areas of an image that have large changes or abrupt transitions in intensity between objects or areas. Because the variance in sharpness indicates how widely the sharpness values are spread throughout the image, a higher variance in sharpness is optimal, as it captures both strong and subtle edges with varying levels of edge enhancement. The Laplacian function was used as the edge-detection technique.  
The formula for obtaining the '\(\alpha\)' optimal value is as follows:  
\[\text{Optimal}\alpha=\text{max}\Bigg{(}\sum_{\alpha=0}^{range}Var\big{(} \ S\big{(}\ CLAHE(I,OC)_{L+\alpha}\big{)}\big{)}\Bigg{)} \tag{2}\]  
'\(\alpha\)' is the additional brightness, function '\(S\)' is sharpness, and '\(OC\)' is the optimal cliplimit.  
Looking at the graphs in Figures 4 and 5, in the case of cliplimit, it can be seen that the variance value converges in a certain range, and in the case of \(\alpha\) (additional brightness), a downward graph is shown. This means that significant computational overhead can occur if an unnecessary iterative process is performed in the process of extracting the optimal value [52].  
Therefore, specifying the optimal value extraction range through the image dataset analysis process in advance can improve processing speed and prevent computational overhead. In this paper, the optimal value extraction range is specified as cliplimit: 0-40; \(\alpha\): 0-10.