# Non-Contact Tilapia Mass Estimation Method Based on Underwater Binocular Vision
## 2 Materials and Methods
### Image Processing and Analysis
#### 2.3.2 Image Enhancement and Stereo Matching  
Because of the uneven illumination of the underwater images obtained from the experiment, this study preprocessed the images before stereo matching. A Retinex-based image enhancement algorithm was used to enhance the underwater images, and the final image was obtained to eliminate the uneven illumination and retain the nature of the fish itself. In this study, several mainstream image enhancement methods were selected for comparison, including single-scale Retinex (SSR), multi-scale Retinex (MSR), and multi-scale Retinex with color restoration (MSRCR). A comparison of the underwater enhancement results is shown in Figure 6.  
Quantitative analysis is needed for images processed by underwater image enhancement methods. In this study, two commonly used image quality evaluation metrics, peak signal-to-noise ratio (PSNR) and structural similarity index (SSIM), were used to quantitatively analyze and compare the performance of different algorithms. In the application of underwater image enhancement, PSNR can be used to determine whether the enhanced image is over-enhanced. Ideally, the enhanced image should be \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Parameter** & \multicolumn{2}{c}{**Left Camera**} & \multicolumn{2}{c}{**Right Camera**} \\ \hline \multirow{2}{*}{Internal parameters} & \(\begin{pmatrix}1757.9769&0&0\\ 0&1739.4673&0\\ 691.2410&350.4650&1\end{pmatrix}\) & \(\begin{pmatrix}1755.6439&0&0\\ 0&1737.4004&0\\ 639.7740&341.6467&1\end{pmatrix}\) \\ \hline \multirow{2}{*}{Radial distortion} & \(k_{1}=0.2938\) & \multicolumn{2}{c}{\(k_{1}=0.2956\)} \\ \cline{2-5}  & \(k_{2}=0.7482\) & \multicolumn{2}{c}{\(k_{2}=0.7320\)} \\ \hline \multirow{2}{*}{Rotation matrix} & \(R=\begin{pmatrix}0.9999&0.0005&-0.0037\\ -0.0005&0.9999&-0.0024\\ 0.0037&0.0024&0.9999\end{pmatrix}\) \\ \hline \multirow{2}{*}{Translation matrix} & \(T=[-60.0704\ 0.0448-0.2057]\) & \multicolumn{2}{c}{} \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Camera calibration results. Figure 6: Underwater image enhancement results based on Retinex: (**a**) original image; (**b**) SSR; (**c**) MSRCR; (**d**) MSR. closer to the reality of the original scene rather than producing unnatural enhancement. A higher PSNR value means that the difference between the enhanced image and the original image is smaller, which usually indicates that the image is of better quality and does not appear to be over-enhanced. The formula for calculating the \(PSNR\) is as follows:  
\[PSNR=10\cdot\log_{10}\left(\frac{MAXX_{A}^{2}}{\frac{1}{mn}\sum\limits_{i=0}^{n }\sum\limits_{j=0}^{n}\left[A(i,j)-B(i,j)\right]^{2}}\right) \tag{5}\]  
In the above formula, \(MAX_{A}\) denotes the maximum pixel value of the image, \(m\) and \(n\) denote the pixel value of each row and column of the image, \(A(i,j)\) denotes the original image, and \(B(i,j)\) denotes the enhanced processed image. The four sets of images in Figure 6 are numbered from 1 to 4. The PSNR values of different algorithms in the same environment are shown in Table 2.  
Table 2 shows that the peak SNR values of MSRCR algorithm were higher than those of the other algorithms for different images in the same environment, which proves that the MSRCR performed well in this index. SSIM is a metric used to assess the similarity between images. It is determined by the covariance between two images. A larger value of SSIM indicates a higher-quality image. When two images are identical, the SSIM is equal to 1. For two images \(x\) and \(y\), the structural similarity index between them can be calculated using a specific formula:  
\[SSIM(x,y)=\frac{(2\mu_{x}\mu_{y}+c_{1})(2\sigma_{xy}+c_{2})}{(\mu_{x}^{2}+\mu_ {y}^{2}+c_{1})(\sigma_{x}^{2}+\sigma_{y}^{2}+c_{2})} \tag{6}\]  
In the above equation, the mean of \(x\) is denoted by \(\mu_{x}\) and the mean of \(y\) is denoted by \(\mu_{y}\).