Image Water Ripple Detection Method Based on Constraint Convolution and Attention Mechanism

Noise can introduce irrelevant interference signals, reduce the signal-to-noise ratio of the image, weaken the contrast between the target and the background, and make it more difficult to detect the target in the image, thus increasing the difficulty of water ripple detection. Therefore, a method for image water ripple detection based on constraint convolution and attention mechanism is proposed. Using the attention mechanism for image denoising, the “attention map” is calculated from both channel and spatial aspects, and the calculated “attention map” is multiplied by the image feature map for adaptive feature learning to achieve image denoising processing. The convolutional neural network is used to extract the features of the input image. Based on feature extraction, the constrained convolution operation is applied to highlight the detailed features of water ripples. The features obtained from the constrained convolution operation are input into the support vector machine classifier for the classification and detection of water ripples. According to the relationship between the patterns and features learned by the classifier, whether the image belongs to the category of water ripples is judged, to achieve water ripple detection. The experimental results show that the proposed method has a good image denoising effect and water ripple detection effect.


Introduction
Water ripples are often caused by factors such as image capture devices, transmission media, or display devices.If left untreated, it may lead to image distortion and quality degradation.Whether it's taking photos, recording videos, or watching TV programs, high-quality images have become an increasingly important demand in people's daily lives [1].When it comes to image quality and visual effects, image water ripple detection methods play an important role.This technology can improve the clarity, detail, and accuracy of images by identifying and correcting water ripples or ripple distortions, thereby improving the viewing experience of users.Therefore, the application of image water ripple detection methods will promote the development of image technology and enhance user satisfaction with image quality [2].
At present, the commonly used methods for image water ripple detection include the Fourier transform method, the Canny edge detection algorithm, and the phase demodulation method.Among them, the image water ripple detection method based on the Fourier transform can obtain the frequency spectrum information of the image by converting the image from the spatial domain to the frequency domain.In the spectrum, water ripples are usually manifested as distinct frequency components.The presence of water ripples can be determined by analyzing the frequency components in the spectrum and setting thresholds.The image water ripple detection method based on Canny edge detection reduces noise by applying Gaussian smoothing filters, and then calculates gradients by using Sobel operators, and finally detects edges in the image by using non-maximum suppression and dualthreshold processing.In images with water ripples, water ripples usually cause edge distortion and deformation.Therefore, the Canny edge detection algorithm can detect these abnormal edge features.The image water ripple detection method based on phase demodulation converts the image from the spatial domain to the frequency domain and can obtain the amplitude spectrum and phase spectrum of the image.Water ripple usually causes distortion and changes in the phase of the image.By demodulating the phase spectrum (for example, by solving the Helmholtz equation), the phase changes affected by water ripples can be extracted and the presence of water ripples can be detected accordingly [3][4][5].In addition to the above methods, the common image detection methods include R-CNN-based image detection methods.This method first extracts candidate regions in the image and then performs convolutional neural network (CNN) feature extraction and classification on each candidate region to achieve image target detection.The SSD-based image detection method uses multiple anchor frames of size and aspect ratio and carries out target detection and classification on different levels of feature maps.
Although the above methods can detect water ripples to a certain extent, they still face some challenges and limitations, such as being susceptible to noise and poor detection performance.Therefore, to detect water ripples more accurately and improve detection performance, a method for image water ripple detection based on constraint convolution and attention mechanism is proposed.

Image denoising based on attention mechanism
The removal of noise in images is a very important step in image processing, as noise can bring a lot of problems such as image quality degradation and loss of key information in the image, which will lead to incorrect judgments in subsequent work.Traditional methods for processing noisy images cannot effectively distinguish between complex noise and natural textures and do not effectively address issues such as loss of image edge information and excessive smoothness of details [6][7][8].In response to the above issues, this article proposes an image-denoising algorithm based on an attention mechanism.
We calculate the "attention map" from both channel and spatial aspects and then multiply the calculated "attention map" with the image feature map for adaptive feature learning, to mine deeper levels of noise in complex backgrounds and improve denoising effectiveness.The following equation is a mathematical representation of the dual attention mechanism, where the feature map is input to the channel attention module for the multiplication operation.
We multiply the feature map obtained from the previous step with the original feature map.
We input the multiplied result into the spatial attention module for operation.
  We multiply the results obtained from the spatial attention module with the results obtained from the channel attention module to obtain the final result.
Based on the above analysis, it can be seen that this attention mechanism is applied from both channel and spatial dimensions, effectively improving the network's feature expression ability without any additional computational loss or parameter increase.The reason for using the dual attention mechanism is that when the channel attention mechanism assigns different weights to each part of the image, the spatial attention mechanism is used to allocate larger weights to the key parts, making the algorithm's attention more focused on the key parts.Image noise covers the entire image, and the dual attention mechanism can better extract noise from complex backgrounds within the entire image range.

CNN-based image water ripple detection
The most important issue in image water ripple detection is the process of extracting target features.The more typical the features are, the better the detection effect is. Traditional detection models use manually designed feature description operators to express target features, which is time-consuming and labor-intensive.In recent years, the convolutional neural network (CNN), which has emerged and flourished, has not only a fast-computing speed but also a rich and diverse feature extraction, thus becoming a basic model for many computer vision studies [9][10].
CNN is a hierarchical database model, mainly composed of the input layer, convolution layer, activation layer, normalization layer, pooling layer, full connection layer, and output layer.The input image of the input layer is calculated forward through multiple alternating convolutional layers, activation layers, normalization layers, and pooling layers to obtain a feature map, gradually changing from low-level features to high-level features.The fully connected layer and output layer then classify the high-level features to obtain the probability score of the target belonging to a certain category label and then output the resulting image with bounding boxes and labels.In this way, based on the functionality of each layer, CNN can be divided into three parts.Among them, the input layer inputs image data separately; A feature extractor composed of a convolutional layer, activation layer, normalization layer, and pooling layer; A feature classifier composed of a fully connected layer and an output layer completes the entire target detection process.
where 1 2 , ,..., k e e e represent the size of the convolution kernel.
(3) Fully connected layer and Softmax layer The input x of the fully connected layer is a vector of 1 N  , which is obtained by tiling the feature values of the previous layer's feature map.The parameter Q of the fully connected layer is a matrix of T N  , where T represents the number of categories to be detected.After the calculation of the fully connected layer, a logic vector logit of size 1 T  is obtained.The value of the logits vector has no size limit, ranging from negative infinity to positive infinity.The Softmax layer will perform logarithmic calculations on the logits vector to obtain prob vectors of the same size.Each value in the prob vector is between 0 and 1, with a total of 1, indicating the probability that the target belongs to each category, which is the output of the final water ripple detection result.

Introduction of constraint constraints for image water ripple detection
From the above analysis, it can be seen that a convolutional neural network can detect image water ripple targets, but because water ripples are very different in different images, a single CNN model may not be able to adapt to all types of water ripples.When dealing with new and diverse water ripple situations, the generalization ability of the model may be limited.Therefore, a constrained convolution-based image water ripple detection method is proposed, which improves CNN through constraints to obtain more excellent detection results.
The image water ripple detection method based on constraint convolution is a technique that utilizes constraint convolution operations to improve the accuracy of water ripple detection.The key idea is to introduce constraint conditions to make the convolutional kernel have a stronger response ability in specific directions or modes, thereby better capturing the detailed features of water ripples.
The following are the main steps of an image water ripple detection method based on constraint convolution: (1) Feature extraction: we use CNN to extract the features of the input image, and after feature extraction, we can obtain the feature representation of the image.
(2) Constraint convolution operation: Based on feature extraction, we apply constraint convolution operation to highlight the detailed features of water ripples.Constrained convolution operations are usually achieved by adding gradient constraints to the convolution layer.By limiting the gradient range or direction in the convolution results, the response of the water ripple region can be emphasized.Specifically, gradient amplitude and direction information can be used to constrain the convolution results: For each pixel position   , x y and its corresponding gradient direction   where   0 0 , x y  represents the expected direction of water ripples.This constraint operation can make the convolutional kernel more sensitive to water ripples in specific modes, thereby better extracting and highlighting the information about water ripples.
(3) Water ripple classification detection: We input the features obtained from constrained convolution operations into a support vector machine classifier for water ripple classification detection.Based on the relationship between the patterns and features learned by the classifier, we determine whether the image belongs to the water ripple category: where 2 w represents the weight vector; x P represents the input feature vector.The image water ripple detection method based on constraint convolution introduces constraint conditions, making the convolution kernel more effective in capturing the detailed features of water ripples.This method has a certain degree of robustness and accuracy and has broad application potential in the field of water ripple detection.

Experiments and result analysis
To verify the detection effect of the image watermarks detection method based on constraint convolution and attention mechanism, Fourier transform method and Canny edge detection algorithm were used as comparative methods for comparative analysis.
The experimental sample images are from the ImageNet dataset, which is a large-scale image dataset developed by Stanford University for research on image recognition and classification tasks.It contains over 1 million high-resolution images, covering approximately 1, 000 categories, such as a wide range of objects, animals, plants, and scenes.Each category has hundreds of thousands of diverse image examples, making it a complex and challenging dataset.We select images with watercontaining ripples as sample images in this dataset and use the above method for image detection.
Noise can introduce additional grayscale changes, leading to a decrease in the contrast of water ripples, and making it difficult to identify and distinguish the undulating parts of water ripples in water ripple detection.To achieve this, first, we compare the image-denoising effects of the Fourier transforms method, the Canny edge detection algorithm, and the proposed method.Peak signal-tonoise ratio (PSNR) is a commonly used index to evaluate image quality.It is measured by calculating the mean squared error (MSE) between the original image and the denoised image.The larger the value is, the better the denoising effect is.The comparison results are shown in Table 1 1, it can be seen that for five different images, the peak signal-to-noise ratio of the proposed method is higher than that of the Fourier transform method and the Canny edge detection algorithm.Among them, the denoising effect for image 5 is the best, with a peak signal-tonoise ratio of 20.31 dB.Compared with the Fourier transform method and Canny edge detection algorithm, the proposed method has improved by 5.79 dB and 5.01 dB, respectively.From this, it can be seen that the proposed method has a better image denoising effect, which can effectively remove noise in the image and is conducive to improving the image water ripple detection effect.
Further, we validate the water ripple detection effect of the proposed method, select any image from the dataset, and verify the detection effects of the three methods.The results are shown in Figure 2.

Figure 2. Image water ripple detection effect
In Figure 2, it can be seen that when we use the proposed method to detect water ripples in the original image, the complete target position can be obtained, and the detection results are relatively clear and complete.However, when we use the Fourier transform method and the Canny edge detection algorithm for water ripple detection, there are problems such as unclear details and missing details.Through comparison, it can be seen that the proposed method has better detection performance and can accurately extract detection targets, fully verifying its detection effect.

Conclusion
To reduce the impact of image noise on the performance of image water ripple detection, a method for image water ripple detection based on constraint convolution and attention mechanism is proposed.The main contributions of this method are as follows: (1) By calculating the "attention map" from both channel and spatial aspects, the calculated "attention map" is multiplied by the image feature map for adaptive feature learning, achieving image denoising and removing noise from the image, and avoiding negative effects of noise on image detection performance.
(2) The convolutional neural network is used to extract the features of the input image.At the same time, the constrained convolution operation is applied to highlight the details of the water ripple.The water ripple classification detection is conducted based on the constrained convolution operation to obtain the detection results of the water ripple.Under the condition of satisfying the constraint convolution, it can better capture the detailed features of water ripples.
(3) The experimental results show that the proposed method has a good image denoising effect, with the highest peak signal-to-noise ratio reaching 20.31 dB, and the water ripple detection effect is good, with clear and complete detection results.

1 c
represents the input characteristic diagram,   G x represents the operation of the channel attention module,   D x represents the operation of the spatial attention module, and   U x represents the calculation result.
, we calculate the constrained result   , H x y :

Table 1 .
. Comparison results of the peak signal-to-noise ratio of different methods