## 3 Design of Improved Multi-Structural Morphology Filtering Approach
### Neighbor-Based Adaptive Fast Median Filtering  
The filtering principle of the median filter is to sort the neighborhoods of a particular pixel in ascending or descending order and use the sorted median value as the pixel value of other pixels in the pixel neighborhood. That is, by selecting a filtering window, sorting the pixels in the window, and assigning the median value to the current pixel, the median filtering result of the entire image can be obtained by iterating through each pixel on the image [48]. The expression for the median filter is as follows:  
\[w(m,n)=median\{f(m-i,n-i),(i,j)eW\} \tag{22}\]  
Figure 7: Results of traditional morphological filtering. At the sea surface of a port, there is a lot of impulse noise, which seriously interferes with the target detection. As such, before vessel detection, the image should be preprocessed to enhance the target vessel and suppress the impulse noise. The traditional median filtering approach uses a fixed-size window, and the loss of subtle points in the image is obvious when filtering [49]. All the pixels in the window must be reordered every time the window is moved; for a window of \(N\) elements, the algorithm complexity is \(O(NlogN)\). This algorithm does not consistently deliver updates as the window moves; therefore, in this study, the fast median filtering based on histogram statistics is adopted. The median value is obtained indirectly by calculating the histogram of the pixels in the window. When the window moves, only the pixels that have moved in and out are updated. A suitable equation is as follows:  
\[T_{avg}(N)=cN+\frac{2}{N}\sum_{i=0}^{N}T_{avg}(i) \tag{23}\]  
where \(T_{avg}(N)\) and \(T_{avg}(i)\) are the average time complexities of the quick sorting of the \(N\) and \(i\)th elements, respectively, and \(c\) is a constant. It has been demonstrated that \(T_{avg}(N)<kNlogN\), where \(k\) is a constant [50]. The de-noising performance of median filtering is related to the density of the input noise signal. If the input noise signal is normally distributed and the mean value is zero, the variance of the output noise signal after median filtering is approximately as follows:  
\[\delta_{med}^{2}=\frac{1}{4 mp^{2}(\overline{m})}=\frac{\delta_{l}^{2}}{m+ \frac{\overline{2}}{2}-1}\times g\frac{\pi}{2} \tag{24}\]  
where \(m\) is the length of the filter window, \(\delta_{l}^{2}\) is the input noise power, \(\overline{m}\) is the mean input noise, and \(P(\overline{m})\) is the input noise density function. From the above formula, the median filtering algorithm will effectively filter out the impulse noise with a pulse width of less than \(\frac{m}{2}\). In order to improve the median filter of a fixed window size and the loss of fine points in the image, the method of increasing the filter window is adopted. At the same time, to avoid misjudging the pixels with higher pixel values at the edge of the target as noise points, the neighborhood pixels are used as the judgment basis for the output. For example, if the window value is [20; 30; 35; 40; 50; 100; 100; 100], 100 is likely to be the target edge point, which is misjudged as noise. Let \(f(i,j)\) be the gray value at the position \((i,j)\) in the image, \(w(m,n)\) be the current filtered window, \(w_{max}(m,n)\) be the maximum filtered window, \(f_{max}(i,j)\) and \(f_{min}(i,j)\) be the maximum, minimum, and median values of gray in the filtered window, respectively, and \(n_{m}\) be the number of pixels in the window equal to \(f_{med}(i,j)\). The process of adaptive median filtering is as follows [51; 52; 53]:  
1. If \(f_{max}(i,j)-f_{med}(i,j)>T\), where T is the threshold, then \(f_{med}(i,j)-f_{min}(i,j)>T\) jumps to step 2; otherwise, increase the window \(w(m,n)\). Then, quickly sort the median values for the new window until the above conditions are met; then the output is \(f(i,j)\). 2. If \(f_{max}(i,j)-f(i,j)>T\), \(f(i,j)-f_{min}(i,j)>T\), then the output is \(f(i,j)\); otherwise, determine whether \(n_{m}>\frac{mm}{3}\) is true.