**4. Our Method**

The key to the image enhancement algorithm based on Retinex lies in the acquisition of illumination map and the restoration of the reflection map and image color. Firstly, we obtain the smoothed image by smoothing the original image, and adding a constant value to the smoothed image as the illumination map *L(x,y)*. The constant value is added to avoid noise in the enhanced image. Then, the reflection map *R(x,y)* is acquired based on an element-wise division according to Retinex with Equation (4).

As the gray value of the reflected map pixels obtained is low, we need to restore the illumination and color of the reflected map. We multiply the reflected map *R(x,y)* directly by a constant coefficient. The bigger the constant coefficient, the bigger the gray value of the corrected image, and the brighter the enhanced image. Experiments were conducted afterward.

Side-scan sonar images are different from natural images, so we considered the following when designing the image enhancement algorithm for side-scan sonar images: (1) Since the side-scan sonar image is originally a gray-scale image and the color side-scan sonar image is the result of pseudo-color processing, we did not use max-RGB technology to obtain illumination map, but directly converted the pseudo-color sonar image into gray-scale. (2) As there is no large change in the gray gradient in side-scan sonar images, we used the mean filter or bilateral filter to directly smooth the gray image of the side-scan sonar image, which not only meets the requirements of gray scale correction of side-scan sonar images, but also improves the speed of the algorithm. (3) In side-scan sonar images, there may be a large area of black area nearby because of a hilltop or raised terrain. Therefore, we added a constant to the smoothed image as the illumination image *L* that avoids much of the noise or "cartoon" phenomena in the black area of the enhanced image. In summary, considering the characteristics of the side-scan sonar image, we propose a side-scan sonar image enhancement algorithm based on Retinex.

According to our proposed algorithm, we use Equation (9) to correct the gray scale of side-scan sonar images:

$$S'(x, y) = A \frac{S(x, y)}{(S(x, y) \otimes F(x, y) + a)}\tag{9}$$

where *S(x,y)* represents the original image, *S*(*x*, *y*) ⊗ *F*(*x*, *y*) + *a* is the illumination map *L*, *F(x,y)* is a smoothing filter function, and *a* is a constant. The constant is mainly used to suppress noise. *A* is a constant coefficient through which the gray value of the corrected image can be adjusted to change the brightness of the corrected image.

The filtering function *F(x,y)* can be used in many filtering methods. Due to the characteristics of side-scan sonar images and considering the time complexity of the algorithm, we choose two methods: Mean filter and bilateral filter. Mean filter is the simplest linear filtering operation. Each pixel of the output image is the average value of the corresponding pixel of the input image in the core window. Mean filtering is the simplest linear filtering operation. Each pixel of the output image is the average value of the corresponding pixel of the input image in the core window. The mean filtering is fast, but does not protect image details well. Bilateral filtering is a non-linear filtering method that combines the spatial proximity and the pixel value similarity of the image. It also considers the spatial information

and gray level similarity. Its advantage is that the algorithm is simple and can protect the image edge, but its disadvantage is that it is slower than mean filtering.

In our algorithm, the parameters A and α are constant. We will provide experiments to analyze the influence of the changes of A and α on the enhancement of side-scan sonar image, and how to select and adjust their respective values.

Our method and SSR method have similarities and differences. The similarities are that both methods are based on Retinex and use smoothing to obtain illumination map. The differences are as follows: (1) Firstly, the SSR method calculates the logarithm of the original image, and then smooths the image with a Gaussian low-pass function to obtain the illumination map. However, our method is to directly smooth the original image with mean filtering or bilateral filtering to obtain the illumination map. (2) The SSR method takes the anti-logarithm operations to restore the illumination of the image. However, the enhanced image often looks unnatural and frequently appears to be over-enhanced. Our method is to multiply the reflectance map directly by a constant to restore the illumination of the image. (3) Our method adds a constant to the smoothed image as the illumination map, which avoids a lot of noise in the enhanced image, while the SSR method fails to avoid the problem of noise generation. Therefore, our method is more suitable for side-scan sonar image enhancement. The following experiments support our conclusion.

Considering the time complexity of the algorithm and the characteristics of side-scan sonar images, we implemented our method by means of mean filtering and bilateral filtering, then analyzed and evaluated the two smoothing schemes through experiments.
