{'fraction_non_alphanumeric': 0.03355192923593107, 'fraction_numerical': 0.010523105078542016, 'mean_word_length': 4.805666223992917, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Single Underwater Image Restoration by Contrastive Learning

Underwater image restoration attracts significant attention due to its importance in unveiling the underwater world. This paper elaborates on a novel method that achieves state-of-the-art results for underwater image restoration based on the unsupervised image-to-image translation framework. We design our method by leveraging from contrastive learning and generative adversarial networks to maximize mutual information between raw and restored images. Additionally, we release a large-scale real underwater image dataset to support both paired and unpaired training modules. Extensive experiments with comparisons to recent approaches further demonstrate the superiority of our proposed method.


Introduction
For marine science and ocean engineering, significant applications such as the surveillance of coral reefs, underwater robotic inspection, and inspection of submarine cables, require clear underwater images. However, raw underwater images with low visual quality can not meet the expectations. The quality of underwater images plays an essential role in scientific missions; thus, fast, accurate, and effective image restoration techniques need to be developed to improve the visibility, contrast, and color properties of underwater images for satisfactory visual quality.
In the underwater scene, visual quality is greatly affected by light refraction, absorption, and scattering. For instance, underwater images usually have a green-bluish tone since red light with longer wavelengths attenuates faster. Underwater image restoration is an ill-posed problem, which requires several parameters (e.g. global background light and medium transmission map) that are mostly unavailable in practice. These parameters can be roughly estimated by employing priors and supplementary information. However, due to the diversity of water types and lighting conditions, conventional underwater image restoration methods fail to rectify the color of underwater images.
Recent advances in deep learning demonstrate dramatic success in different fields. Learning-based models require a large-scale dataset for training, which is often difficult to obtain. Thus, most learning-based models use either small-scale real underwater images [9,7], synthesized images [8,3], or natural in-air images [10] as either the source domain or target domain of the training set, instead of using the restored underwater images as the target domain. The aforementioned datasets are limited to capture natural variability in a wide range of water types.
To overcome the earlier discussed challenges, we construct a large-scale real underwater image dataset with accurate restored underwater images. We formulate the restoration problem as an image-to-image translation problem and propose a novel Contrastive UnderWater Restoration approach (CWR). Given an underwater image as the input, CWR directly outputs a restored image showing the real color of underwater objects as if the image was taken inair without any structure and content loss.
The main contribution of our work is summarized as: • We propose CWR, which leverages contrastive learning to maximize the mutual information between corresponding patches of the raw image and the restored image to capture the content and color feature correspondences between two image domains.
• We construct a large-scale, high-resolution underwater image dataset with real underwater images and restored images. This dataset supports both paired or unpaired training. Our code and dataset are available on GitHub.

A Novel Dataset
Heron Island Coral Reef Dataset (HICRD) contains raw underwater images from eight sites with detailed metadata for each site, including water types, maximum dive depth, wavelength-dependent attenuation within the water column, and the camera model. According to raw images' depth information and the distance between objects and the camera, images with roughly the same depth and constant distance are labeled as good-quality. Images with sharp depth changes or distance changes are labeled as lowquality. We apply our imaging model described in section 3 to good-quality images, producing corresponding restored images, and manually remove some restored images with non-satisfactory quality.
HICRD contains 6003 low-quality images, 3673 goodquality images, and 2000 restored images. We use lowquality images and restored images as the unpaired training set. In contrast, the paired training set contains goodquality images and corresponding restored images. The test set contains 300 good-quality images as well as 300 paired restored images as reference images. All images are in 1842 x 980 resolution.

Underwater Imaging Model
Unlike the dehazing model [5], absorption plays a critical role in an underwater scenario. Each channel's absorption coefficient is wavelength-dependent, being the highest for red and the lowest for blue. A simplified underwater imaging model [14] can be formulated as: is the medium transmission describing A(x) the portion of light that is not scattered, β c is the light attenuation coefficient and d(x) is the distance between camera and object. Channels are in RGB space.
Transmittance is highly related to β c , which is the light attenuation coefficient of each channel, and it is wavelength-dependent. Unlike previous work [13,2], instead of assigning a fixed wavelength for each channel containing bias (e.g., 600nm, 525nm, and 475nm for red, green, and blue), we employ the camera sensor response to conduct a more accurate estimation. Figure 1 shows the camera sensor response of sensor type CMV2000-QE used in collecting the dataset.
The new total attenuation coefficient is estimated by: where p c is the total attenuation coefficient, β λ is the attenuation coefficient of each wavelength, and S c (λ) is the camera sensor response of each wavelength. Following the human visible spectrum, we set a = 400nm and b = 750nm to calculate the medium transmission for each channel. We modify t c (x) in equation 1 leading to a more accurate esti- It is challenging to measure the scene's actual distance from an individual image without a depth map. Instead of using a flawed estimation approach, we assume the distance between the scene and the camera to be small (1m -5m) and manually assign a distance for each good-quality image.
The global atmospheric light, A c is usually assumed to be the pixel's intensity with the highest brightness value in each channel. However, this assumption often fails due to the presence of artificial lighting and self-luminous aquatic creatures. Since we have access to the diving depth, we can define A c as follows: where p c is the total attenuation coefficient, φ is the diving depth.
With the medium transmission and global atmospheric light, we can recover the scene radiance. The final scene radiance J(x) is estimated as: Typically, we choose t 0 = 0.1 as a lower bound. In practice, due to image the formulation's complexity, our imaging model may encounter information loss, i.e., the pixel intensity values of J c (x) are larger than 255 or less than 0. This problem is avoided by only mapping a selected range (13 to 255) of pixel intensity values from I to J. However, outliers may still occur; we re-scale the whole pixel intensity values to enhance contrast and keep information lossless after restoration.

Method
Given two domains X ⊂ R H×W ×3 and Y ⊂ R H×W ×3 and a dataset of unpaired instances X containing raw underwater images x and Y containing restored images y. We denote it X = {x ∈ X } and Y = {y ∈ Y}. We aim to learn a mapping G : X → Y to enable underwater image restoration.

Loss type Equation No. Equation
Cross-entropy 7 Table 1. Components of the full objective. We use least-square adversarial loss for equation 6. For equation 7, we use a noisy contrastive estimation framework to maximize the mutual information between inputs and outputs. The idea behind equation 7 is to correlate two signals, i.e., the "query" and its "positive" example, in contrast to other examples in the dataset (referred to as "negatives"). We map query, positive, and N negatives to K-dimensional vectors and denote them v, v + ∈ R K and v − ∈ R N ×K , respectively. Note that v − n ∈ R K denotes the n-th negative. We set up an (N + 1)-way classification problem and compute the probability that a "positive" is selected over "negatives". This can be expressed as a cross-entropy loss where cos(u, v) = u v/ u v denotes the cosine similarity between u and v. τ denotes a temperature parameter to scale the distance between the query and other examples, we use 0.07 as default. For equation 8, We select L layers from Genc(X) and send them to a projection head HX , embedding one image to a stack of feature {z l } L = H l G l enc (x) L , where G l enc represents the output of l-th selected layers. After having a stack of features, each feature actually represents one patch from the image. We denote the spatial locations in each selected layer as s ∈ {1, ..., S l }, where S l is the number of spatial locations in each layer. We select a query each time, refer the corresponding feature "positive" as z s l ∈ R C l and all other features ("negatives") as z S\s l ∈ R (S l −1)×C l , where C l is the number of channels in each layer. An Identity loss is introduced to prevent the generator from unnecessary changes. Equation 9 is a 1 Identity loss preserving the fidelity.
Contrastive UnderWater Restoration (CWR) has a generator G as well as a discriminator D. G enables the restoration process, and D ensures that the images generated by G are undistinguished to domain Y in principle. The first half of the generator is defined as an encoder while the second half is a decoder, presented as G enc and G dec respectively.
We extract features from several layers of the encoder and forward them to a two-layer MLP projection head H. Such a projection head learns to project the extracted features from the encoder to a stack of features. CWR combines three losses, including Adversarial loss, PatchNCE loss, and Identity loss. The details of our objective are described below.
The restored image should be realistic (L GAN ), and patches in the corresponding raw and restored images should share some correspondence (L PatchNCE ). The restored image should have an identical structure to the raw image. In contrast, the colors are the true colors of scenes (L Identity ). The full objective is: We set λ GAN = 1, λ N CE = 1, and λ IDT = 10. The details of each component are elaborated in Table 1.
We train CWR, CUT, and CycleGAN for 100 epochs with the same learning rate of 0.0002. The learning rate decays linearly after half epochs. We load all images in 800x800 resolution, and randomly crop them into 512x512 patches during training. We load test images in 1680x892 resolution for all methods. The architecture of CWR is inspired by CUT, a Resnet-based generator with nine residual blocks and a PatchGAN discriminator. We employ spectral normalization for discriminator and instance normalization for generator. The batch size is 1 and the optimizer is Adam.

Evaluation Protocol and Results
To fully measure the performance of different methods, we employ three full-reference metrics: mean-square error (MSE), peak signal-to-noise ratio (PSNR), and structural similarity index (SSIM) as well as a non-reference metric designed for underwater images: Underwater Image Quality Measure (UIQM) [11]. A higher UIQM score suggests the result is more consistent with human visual perception. We additionally use Fréchet Inception Distance (FID) [6] to measure the quality of generated images. A lower FID score means generated images tend to be more realistic. Table 2 provides quantitative evaluation, where no method always wins in terms of all metrics. However, CWR performs stronger than all the baselines. Figure 2 presents the randomly selected qualitative results. Conven-Input CUT [12] CycleGAN [15] UWCNN [8] Retinex [4] Fusion [1] DCP [5] IBLA [13] CWR (ours) Ground Truth Figure 2. Qualitative results on the test set of HICRD. CWR shows visual satisfactory results without content and structure loss. tional methods produce blurry and unrealistic results, while learning-based methods tend to rectify the distorted color successfully. CWR performs better than other learningbased methods in keeping with the structure and content of the restored images identical to raw images with negligible artifacts.

Conclusion
This paper presents an underwater image dataset HICRD that offers large-scale underwater images and restored images to enable a comprehensive evaluation of existing underwater image enhancement & restoration methods. We believe that HICRD will make a significant advancement for the use of learning-based methods. A novel method, CWR employing contrastive learning is proposed to capitalize on HICRD. Experimental results show that CWR significantly performs better than several conventional methods while showing more desirable results compared to learningbased methods.