# Attention-Based Mechanism and Adversarial Autoencoder for Underwater Image Enhancement
## 2 Materials and Methods
### Loss Function  
The loss function of the proposed UW-AAE model in this study comprises two main components: the Color-AE module \(L_{f}\) and the adversarial network module \(L_{\text{GAN}}\). \(L_{f}\) is a linearly optimized combination of the reconstruction loss function \(L_{1}\) and the perceptual loss function \(L_{\text{VGG}}\), utilized to train the Color-AE module. The final loss \(L_{f}\) is expressed as follows:  
\[L_{f}=L_{1}+\lambda L_{\text{VGG}} \tag{12}\]  
The hyperparameter \(\lambda\) is used as a trade-off factor to balance the weights of the loss functions \(L_{1}\) and \(L_{\text{VGG}}\). In this study, \(\lambda\) is set to 0.05. \(L_{1}\) represents the difference between the reconstructed result \(\hat{K}\) and the corresponding true data \(K\), and can be expressed as follows:  
\[L_{1}=\sum_{m=1}^{H}\sum_{n=1}^{W}\left[\hat{K}(m,n)-K(m,n)\right]^{2} \tag{13}\]  
To enhance the visual quality of the image, the VGG19 pre-training model [27] is incorporated into the framework. The perceptual loss, denoted as \(L_{\text{VGG}}\), is computed based on the disparity between the reconstructed image response from the convolutional neural network and the feature mapping of the target image. Here, \(\phi_{k}\) represents the high-level feature extracted from the \(k\)th convolutional layer. The distance between the reconstructed result \(\hat{K}\) and the feature representation of the ground truth image \(K\) is defined as follows:  
\[L_{\text{VGG}}=\sum_{m=1}^{H}\sum_{n=1}^{W}\left|\phi_{k}(\hat{K})(m,n)-\phi_{ k}(K)(m,n)\right| \tag{14}\]  
This formula delineates the establishment of a perceptual loss at each pixel position \((m,n)\) through the computation of the absolute disparity between the feature representations of the reconstructed image and the truth image at feature layer \(k\). This perceptual loss is computed as the disparity between the reconstructed image and the truth image. This metric of disparity serves to gauge the semblance between the reconstructed image and the truth image within the feature space. This methodology offers the advantage of proficiently steering the optimization of the reconstructed image, circumventing the necessity for real data, which can be arduous to acquire.  
The generator \(G\) in the adversarial network serves as the encoder of Color-AE, generating negative samples denoted as \(z_{-}\). In other words, \(z_{-}=\text{En}(x)\). The discriminator receives both the positive samples \(z_{+}\) from the encoder of the pre-trained CNN-AE and the negative samples \(z_{-}\). The loss function of the discriminator in the adversarial network is given as follows:  
\[L_{\text{GAN}}=\underset{G}{\text{minmax}}\text{max}E_{z_{+}\sim p_{z_{+}}}[ \log D(z_{+})]+E_{x\sim P_{\text{data}}}[\log(1-D(En(x)))] \tag{15}\]  
Figure 7: Feature fusion module.  
where \(p_{z_{+}}\) represents the hidden space distribution of the pre-trained model CNN-AE, and \(P_{\text{data}}\) is the training data distribution. Through adversarial training, \(p_{z_{+}}\), is enforced to approach the hidden space of Color-AEE.