Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 10, No. 1, 2024 12 Analysis of Image Processing Algorithms for Water Surface Garbage Cleaning Robots Wencheng Wang1, 2, Quandi Wu3, Fa Huang1, 2, Guoqing Cai1, 2 and Lijie Zhou1, 2 1Department of Mechanical Engineering, Hebei University of Water Resources and Electric Engineering, Cangzhou, Hebei 061000, China 2Hebei Industrial Manipulator Control and Reliability Technology Innovation Center, Cangzhou, Hebei 061000, China 3College of Mechanical and Electrical Engineering, Hebei Normal University of Science & Technology, Qinhuangdao, Hebei 066000, China Abstract: To facilitate the observation of the water surface conditions in front of the water surface garbage cleaning robots during navigation, an image transmission function was designed using cameras and wireless transmission equipment. However, due to the influence of water surface lighting, the transmitted images were unclear. In this paper, five image processing algorithms were written in Python language using the OpenCV library: Histogram Equalization, Gray World Algorithm, Retinex-based Enhancement Algorithm, Automatic White Balance (AWB) Algorithm, and Automatic Color Equalization (ACE) Algorithm. The algorithms were used on both static and dynamic water surface images, and the program results showed that the Automatic Color Equalization (ACE) Algorithm is the most appropriate image processing algorithm for water surface garbage cleaning robots. Keywords: Image Processing Algorithms, Water Surface Garbage Cleaning Robots, OpenCV, Python. 1. Introduction In recent years, the problem of water garbage pollution in China has become increasingly serious. Various types of floating garbage not only destroy the aquatic environment but also pose severe threats to the health of residents living nearby. To effectively address this issue, small and intelligent water surface garbage cleaning robots have emerged. These robots can automatically clean floating waste on the surface of urban lakes, water channels, or rivers, greatly improving the safety of residents’ water use. However, in practical applications, the images captured by cameras often suffer from lighting interference due to sunlight and water surface reflections, leading to decreased image quality[1,2]. Therefore, eliminating the influence of lighting to improve image quality has been an urgent problem to solve. Regarding the problem of lighting effects, image processing technology plays a key role. Researchers at home and abroad have made significant progress in this field. One widely studied method is the use of image enhancement techniques, including Histogram Equalization, Contrast Stretching, and Gamma Transformation[3]. Another effective method is the use of machine learning or deep learning models to identify and eliminate lighting interference[4]. Additionally, some researchers have attempted to combine physical models with image processing techniques to counteract the influence of lighting based on optical principles such as reflection, refraction, and scattering to establish lighting models and compensation algorithms[5]. By accurately estimating lighting parameters, these algorithms can somewhat eliminate the impact of uneven lighting on image quality. However, despite some progress in removing lighting effects, many challenges and problems still need to be addressed. This paper has written five image processing algorithms using Python language and OpenCV library and performed a comparative analysis to find the most suitable image processing algorithm for water surface garbage cleaning robots. 2. Basic Steps of Image Processing Algorithms To address the impact of water surface lighting on image quality, this paper studied five image processing algorithms: Histogram Equalization, Gray World Algorithm, Retinex- based Enhancement Algorithm, Automatic White Balance (AWB) Algorithm, and Automatic Color Equalization (ACE) Algorithm. Here’s the basic idea of each of these five algorithms. 2.1. Basic steps of Histogram Equalization Algorithm Histogram Equalization is an image processing technique used to enhance image contrast, especially in images where the background and foreground are too bright or too dark. Its basic principle involves transforming the image histogram so that the resulting image has an approximately uniform cumulative distribution function, thereby improving the image’s contrast. The steps of the Histogram Equalization Algorithm are: (a) Compute the image’s gray level histogram. Calculate the histogram’s cumulative distribution function (CDF), usually a monotonically increasing function between 0 and the image’s maximum gray level (e.g., 255 in an 8-bit image). Use the CDF to map the image’s old gray levels to new gray levels, which are directly determined by the CDF values, thus expanding the image’s gray level range. Update the image’s pixel values using the mapping to enhance the contrast. 2.2. Basic steps of the Gray World Algorithm The Gray World Algorithm (Gray World Assumption) is a simple and effective white balance image processing method based on an assumption: in an image, the average reflected light color should be gray, i.e., the average brightness of each color channel should be approximately equal. The Gray 13 World Algorithm applies this assumption to the image to be processed, eliminating the influence of ambient light and obtaining the original image. The steps of the Gray World Algorithm (in an RGB image with channel values from 0-255) are: For each pixel in the image, read the values of its R, G, and B channels. Calculate the average value for each channel: NRR avg ; NGG avg ; NBB avg (1) where N represents the total number of pixels in the image. Calculate the total average value of each channel’s average value:   3avgavgavgavg BGRGray  (2) Calculate the adjustment ratio for each channel: RGrayR avgavgScale  ; GGrayG avgavgScale  (3) BGrayB avgavgScale  Readjust the R, G, and B channel values of each pixel according to the calculated ratio: RRR Scale ; GGG Scale ; BBB Scale (4) Use R’, G’, and B’ to compose the processed image. 2.3. Basic steps of Multi-Scale Retinex Algorithm The Retinex-based Enhancement Algorithm (Retinex), based on the principle of how the human visual system processes information, is used to enhance images. The Retinex Algorithm tries to simulate the human visual system’s processing of images to achieve color constancy and dynamic range compression similar to human vision. The Multi-Scale Retinex (MSR) Algorithm steps are as follows: (a) Gaussian blurring of the original image at each scale to obtain a blurred image, where the subscript i represents the scale number. (b) Sum up the calculations at each scale: )],(log[)],(log[*)()],(log[)],(log[ yxLyxIiWeightyxRyxR iii  (5) where Weight(i) represents the corresponding weight at each scale, and the sum of weights across all scales must be 1, classically chosen as equal weight. 2.4. Automatic White Balance Algorithm (AWB) Automatic White Balance is an image processing algorithm designed to correct color biases in images so that they appear more natural. These biases are usually caused by incorrect light sources, color temperatures, or camera settings. The principle of the Automatic White Balance Algorithm is to adjust brightness and color according to the image’s color information to achieve balance. The steps of the Automatic White Balance Algorithm are: (a) Obtain a grayscale image: convert the input image into a grayscale image for subsequent processing. (b) Calculate color gains: by analyzing the different color channels in the image, calculate the color gain coefficients for each channel. These coefficients are used to adjust the brightness of each channel. (c)Calculate the brightness gain: extract an average value from the color gains, then allocate that average value to each channel to adjust the overall brightness. (d)Apply gains: apply the brightness gain and color gains to each channel of the image. This can be achieved by multiplying the RGB values of each pixel by the corresponding gain coefficients. (e)Remap pixel values: remap the brightness range of the image according to the adjusted pixel values to ensure the image has a proper contrast. 2.5. Automatic Color Equalization Algorithm (ACE Algorithm) The ACE Algorithm originates from the Retinex Algorithm and can adjust image contrast to achieve the constancy of human eye color and brightness. It considers the spatial relationships of color and brightness in the image, performing adaptive filtering of local features, achieving local and non- linear features of image brightness and color adjustment and contrast adjustment while meeting both the Gray World Assumption and the White Patch Assumption. The steps of the Automatic Color Equalization Algorithm are: (a) Adjust the image for color/spatial distribution, completing color correction, and obtaining the spatially reconstructed image;     pjSubsetj cc c jpd pIpIr pR , ),( ))()(( )( (6) Rc is the intermediate result, Ic(p)-Ic(j) is the brightness difference between two different points, d(p,j) represents the distance metric, and r(x) is the brightness representation function which needs to be an odd function; this step can adapt the local image contrast, r(x) can amplify smaller differences and enrich larger ones, expanding or compressing the dynamic range according to local content. Generally, r(x) is:          Tx TxTT x Tx xr , 1 , , 1 )( (7) (b) Dynamic range extension of the corrected image. The ACE Algorithm is applied to a single color channel. For a color image, it is necessary to process each color channel separately, with one simple linear expansion being: )](*5.127[ pRwroundxR c)( (8) where w represents the slope of the line segment [(0,mc),(255,Mc)], and )]([min pRcmC  , )](max[C pRcM  (9) 14 (c) Using the following formula, expand R(x) to the range [0,1], resulting in the enhanced channel RR RxR xL minmax min)( )(    (10) 3. Analysis of Image Processing Results of The Five Algorithms Four original images are selected as shown in Figure 1. Images 1(a) and 1(b) are relatively static water surfaces with less light reflection, while images 1(c) and 1(d) are dynamic water surfaces with more pronounced lighting reflections. The five image processing algorithms developed were applied to the four images, and the results are presented in Figures 2 to Figures 6. (a) (b) (c) (c) Figure 1. Original images of water surface garbage (a) (b) (c) (d) Figure 2. Results of Histogram Equalization Algorithm Image Processing By comparing the images before and after the Histogram Equalization Algorithm process shown in Figures 1 and 2, it can be seen that after processing the images with the Histogram Equalization Algorithm, the display of floating garbage on the water surface in images (a) and (b) is significantly enhanced. However, for images (c) and (d), the presence of dynamic water ripple patterns causes the enhancement of the ripple image signals without improving the signal of the floating garbage. From the analysis above, it is clear that the Histogram Equalization method of image processing works well for relatively calm water surfaces, but when wind causes water ripples or dynamic situations, the complex lighting reflections may lead to image saturation in certain areas and extreme brightness, which degrades the processing effect. Thus, this method is unsuitable for processing the robot’s return images. (a) (b) (c) (d) Figure 3. Results of Gray World Algorithm Image Processing By comparing the images before and after the Gray World Algorithm processing shown in Figures 1 and 3, it can be seen that after processing the images with the Gray World Algorithm, the display enhancement of floating garbage on the water surface has improved for all four images. However, for image (d), due to the presence of dynamic water ripples and strong lighting reflection signals, the signal enhancement effect of the floating garbage is not ideal. From the analysis above, the Gray World method of image processing is effective for scenes without severe color biases (relatively calm water surfaces with non-intense light); however, it performs poorly for images with special lighting effects and is thus unuitable for processing the robot’s return images. (a) (b) (c) (d) Figure 4. Results of Retinex-based Enhancement Algorithm Image Processing Comparing the images before and after the Retinex-based Enhancement Algorithm processing in Figures 1 and 4 shows that the display of floating garbage on the water surface worsens for all four images after treatment with the Retinex Algorithm. 15 (a) (b) (c) (d) Figure 5. Results of Automatic White Balance Algorithm Image Processing Comparing the images before and after the Automatic White Balance Algorithm process in Figures 1 and 5 reveals that the display of floating garbage on the water surface for all four images has improved after the processing. However, in image (d), the reflection light from the dynamic ripples is not effectively filtered. (a) (b) (c) (d) Figure 6. Results of Automatic Color Equalization Algorithm Image Processing By comparing the images before and after the Automatic Color Equalization Algorithm process in Figures 1 and 6, it can be observed that after processing the images with the Automatic Color Equalization Algorithm, a significant improvement is seen in the display clarity of floating garbage on the water surface across all four images, with almost negligible light impact. Comparing the image processing results of static and dynamic water surfaces with the five methods indicates that the Retinex-based Enhancement Algorithm (Retinex Algorithm) has the worst image processing effect; although the Histogram Equalization Algorithm removes the impact of lighting on the image, it inherently converts color images to grayscale images, which are not as clear as color images. The Gray World and Automatic White Balance (AWB) algorithms do not perform well for dynamic water surface processing; Automatic Color Equalization (ACE) Algorithm reveals clear visibility for floating garbage under static and dynamic water surfaces, with negligible light influence. Consequently, the Automatic Color Equalization (ACE) Algorithm can be used for image processing to resolve the problem of illumination impact on water surface images, as analyzed. 4. Conclusion This paper aimed to resolve the issue of lighting affecting the clarity of images transmitted by cameras, comparing five types of image processing algorithms: Histogram Equalization Algorithm, Gray World Algorithm, Retinex- based Enhancement Algorithm, Automatic White Balance (AWB) Algorithm, and Automatic Color Equalization (ACE) Algorithm. Each method has been programmatically implemented using Python language and the OpenCV library, purposefully selecting images from static and dynamic lake surfaces under illumination. The images were processed using the five methods, and through the analysis of the results, a suitable image processing algorithm for the project was selected: Automatic Color Equalization (ACE) Algorithm. Acknowledgment Funded by Science Research Project of Hebei Education Department (ZD2021329). References [1] Liu Bin, ZHAO Da Quan, Deng Weijun. Surface floater automatic cleaning robot [J]. Electric technology, 2021, (02) : 31 + 30-77. [2] TANG Zhenyu, Zheng Zhihao, LIANG Jiarui et al. Design of visual identification system for surface garbage of unmanned cleaning ship [J]. Journal of Guangzhou Institute of Navigation,2023,31(04):5-10. [3] Yin Qingfei. Research on ship navigation environment visualization based on image processing technology [J]. Ship Science and Technology,2023,45(13):150-153. [4] Guo Chunyu, XU Jing-Jing, Han Yang et al. Development and application of particle image velocity measurement technology in ship field [J]. Chinese Ship Research,2021,16(06):84- 91+150. [5] Yao Hongbing, Huang Yin, Bian Jinwen et al. Imaging processing and calibration of surface vessel [J]. Advances in Laser and Optoelectronics,2018,55(08):255-260.