## 3 Improved TSETMF Algorithm
### TSETMF Concept  
The concept of the improved TSETMF algorithm can be stated as follows. After a grayscale noise image with matrix \(M\times N\) is input, the initial filter window size can be set as 3 \(\times\) 3. Firstly, taking the center of the initial filter window to coincide with the first 3 \(\times\) 3 region center, window \(B\) can be expressed as:  
\[B= \begin{pmatrix}a_{11}&a_{12}&a_{13}\\ a_{21}&a_{22}&a_{23}\\ a_{31}&a_{32}&a_{33}\end{pmatrix}  \tag{6}\]  
where the gray levels of nine pixels can be shown as \(a_{11}\), \(a_{12}\), \(a_{13}\), \(a_{21}\), \(a_{22}\), \(a_{23}\), \(a_{31}\), \(a_{32}\), and \(a_{33}\) and parameter \(a_{ij}\) represents the element at row \(i\) and column \(j\) in the 3 \(\times\) 3 window. Afterwards, a threshold value \(T_{K}\) (\(K\) represents the threshold value numbers: K = 0, 1, 2, 3,...) can be set. At this stage, if the pixel values at \(a_{ij}\) differ from one another, the window pixel probability \(P_{11}=P_{12}=\ldots\)\(P_{ij}\ldots=P_{33}=1/9\) (\(L\) = 9). Assuming that the threshold values \(s\), \(t\) can be used to realize segmentations, foreground probability \(P_{0}\) and background probability \(P_{1}\) can be obtained. The threshold values can be expressed as:  
\[s,t\in\big{(}a_{ij},s<t\big{)}. \tag{7}\]  
The Shannon entropy \(H_{0}\) and \(H_{1}\) of the target and background gray-level distributions can be individually calculated as:  
\[\left\{ \begin{array}{l}H_{0}=-\sum\limits_{i=0}^{s}\sum\limits_{j=0}^{t} \frac{p_{ij}}{P_{0}}\ln\frac{p_{ij}}{P_{0}}\\ H_{1}=-\sum\limits_{i=s+1}^{L-1}\sum\limits_{j=t+1}^{L-1}\frac{p_{ij}}{P_{1}} \ln\frac{p_{ij}}{P_{1}}.\end{array} \right. \tag{8}\]  
Taking the image's gray-level distributions and the amount of information between different gray levels into account, the threshold value \(T_{K}\) can be defined based on the entropy difference calculation in the two-dimensional maximum Shannon entropy, i.e.,  
\[T_{k}=\text{arg}\underset{0<t<L-1}{\text{min}}|H_{0}-H_{1}|^{2}. \tag{9}\]  
Then, the sum of the pixel difference \(D_{1}\) between the filtering window's central values and neighboring areas can be calculated as:  
\[D_{1}=sum|a_{ij}-a_{22}|. \tag{10}\]  
Correspondingly, the average value \(D\) of the pixel difference can be expressed as:  
\[D=\frac{D_{1}}{9}. \tag{11}\]Then, the average value \(D\) is taken and compared with the entropy threshold \(\mathrm{T_{K}}\). If \(D>T_{K}\), it may be regarded as noise. Conversely, it may be regarded as non-noise. By updating each function value, the next pixel point can be calculated. In addition, if a noise point has been identified in a \(3\times 3\) window, the filter window can be adjusted to \(5\times 5\). Each function value can be updated using the pixel values in the current filter window. Correspondingly, the gray values in the new window area can be regarded as \(b_{\bar{y}}\) (\(i\), \(j\) = 1, 2, 3, 4, 5). Assuming that \(D<T_{K}\), this pixel value can be viewed as a normal, undamaged pixel value; otherwise, the median value is employed to replace it and the filtering process is conducted. By updating each value, the next pixel will be addressed until all pixels in the targeted image have been processed completely. It should be noted that when making noise judgments, \(3\times 3\) and \(5\times 5\) windows may be used when processing. They also may be utilized to conduct the median replacement for a low-density-noise grayscale image. However, along with an increase in high-density noise, the probability of non-noise pixel points decreases, which may result in poor image denoising effects. Hence, in the proposed improved TSETMF algorithm, median filter pixel replacement is conducted using the \(5\times 5\) window. In the proposed TSETMF algorithm, a \(3\times 3\) window can be used first to conduct noise judgment. If the central value of the window is judged as non-noise, it is not utilized in the subsequent filtering process with minor computational effort.