# Adaptive Edge Preserving Weighted Mean Filter for Removing Random-Valued Impulse Noise

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

- We propose an adaptive noise detector and a new weighted mean filter to remove random valued impulse noise from the images.
- In contrast to other state-of-the-art noise detectors, the proposed detector computes a novel adaptive threshold for each pixel. The accuracy of the detection scheme is further enhanced by employing additional steps to avoid faulty detection of edge pixels, which are noisy pixels. This step indeed ensures the preservation of the edges avoiding faulty detection of noise.
- In the filtering stage, a novel weighted mean filter is designed to filter only those pixels which are identified as noisy in the detection stage. In contrast to the existing filtering techniques, the proposed filter first divides the pixels into clusters of clean and noisy pixels. Then, to design the filter, only clean pixels are utilized to find the replacement of the noisy pixel.

## 2. Proposed Noise Detection Scheme

#### 2.1. Calculation of Separating Threshold

- Let ${x}_{i,j}$ be the pixel under observation at location $(i,j)$ to know whether it is noise or clean, then it is considered as a central pixel. Window of the size found in Equation (2) is set around the central pixel.
- The corresponding pixel values of of the current window are sorted in ascending order in vector $\mathbf{s}$. The outliers are removed from $\mathbf{s}$ by adopting the “three sigma rule” with median absolute deviation (MAD) [21]. The MAD for $\mathbf{s}$ is found as:$$\mathrm{MAD}=\mathrm{median}\mid \mathbf{s}-\mathrm{median}(\mathbf{s}).\mid $$Vector $\mathbf{s}$ is searched, and, if the difference between any value in $\mathbf{s}$ and the median value is greater than $3\times \mathrm{MAD}$, it is considered as an outlier and is not taken into account for further calculation. After removal of outliers, let ${\mathbf{s}}_{\mathbf{n}}$ be the resultant vector, where n denotes the size of ${\mathbf{s}}_{\mathbf{n}}$.
- Compute the absolute difference ${d}_{k}$ between every two adjacent pixels in ${\mathbf{s}}_{\mathbf{n}}$ as:$${d}_{k}=\mid {s}_{k}-{s}_{k+1}\mid ,$$
- The separating threshold ${\gamma}_{s}$ is found as:$${\gamma}_{s}=m+{e}^{\frac{1}{\sigma /100}},$$$$m=\frac{1}{n-1}\sum _{k=1}^{n-1}d(k).$$

#### 2.2. Separation of Pixels into Clusters

- Initialize from the first pixel in sorted vector ${\mathbf{s}}_{\mathbf{n}}$. If the difference between current pixel ${s}_{i}$ and next pixel ${s}_{i+1}$ is less than or equal to ${\gamma}_{s}$, keep the pixel ${s}_{i+1}$ in the current group together with ${s}_{i}$.
- However, if the difference is greater than ${\gamma}_{s}$, finish the current group and start a new group, such that the first element of the new group will be ${s}_{i+1}$. Apply the same procedure until the last element of vector ${\mathbf{s}}_{\mathbf{n}}$.
- The clean and noisy groups are decided based on the size of the group. The first two largest clusters are considered as clean clusters while all other clusters are considered as noisy and are discarded. The clean clusters are denoted as ${\mathbf{g}}_{\mathbf{1}}$ and ${\mathbf{g}}_{\mathbf{2}}$. Cluster ${\mathbf{g}}_{\mathbf{1}}$ is used in the detection phase while ${\mathbf{g}}_{\mathbf{1}}$ and ${\mathbf{g}}_{\mathbf{2}}$ are used in filtering.

#### 2.3. Noise Detection

#### 2.4. Edge Pixel Identification

- Keeping ${x}_{i,j}$ as a reference pixel, pixels present along four directions are taken into account. These four directions ${\mathit{\theta}}_{A}$, ${\mathit{\theta}}_{B}$, ${\mathit{\theta}}_{C}$ and ${\mathit{\theta}}_{D}$ are illustrated in Figure 3.
- ${\mathit{\theta}}_{A}^{\prime}$ contains the pixels from the direction ${\mathit{\theta}}_{A}$ excluding ${x}_{i,j}$. Similarly, ${\mathit{\theta}}_{B}^{\prime}$, ${\mathit{\theta}}_{C}^{\prime}$ and ${\mathit{\theta}}_{D}^{\prime}$ contain the pixels from the directions ${\mathit{\theta}}_{B}$, ${\mathit{\theta}}_{C}$ and ${\mathit{\theta}}_{D}$, respectively, excluding ${x}_{i,j}$.
- Find the absolute difference between central pixel ${x}_{i,j}$ with all pixels along direction ${\mathit{\theta}}_{A}^{\prime}$. The difference vector is defined as ${\mathbf{d}}^{\mathbf{A}}$ = $\mid {x}_{i,j}-{\mathit{\theta}}_{A}^{\prime}\mid $.
- ${\mathbf{d}}^{\mathbf{A}}$ is searched to find the values less than or equal to m. Indexes of pixels corresponding to these values are identified in ${\mathit{\theta}}_{A}$. These pixels are stacked in vector $\mathbf{v}$. The vector $\mathbf{v}$ is considered to be an edge if total number of pixels in $\mathbf{v}$ is at least 50% of direction ${\mathit{\theta}}_{A}$. Step 4 is only performed if this condition holds true. Otherwise, discard the $\mathbf{v}$ and go to step 5.
- Take the standard deviation of central pixel ${x}_{i,j}$ with $\mathbf{v}$. The pixel is identified as an edge if standard deviation of $\mathbf{e}$ and ${x}_{i,j}$ is less than or equal to threshold $\gamma $:$$\begin{array}{c}\hfill {x}_{i,j}=\left\{\begin{array}{cc}\mathrm{Edge},\hfill & \mathrm{if}\phantom{\rule{4.pt}{0ex}}\mathrm{std}(\mathbf{v},{x}_{i,j})\phantom{\rule{4pt}{0ex}}\le \gamma ,\hfill \\ \mathrm{Go}\phantom{\rule{4.pt}{0ex}}\mathrm{to}\phantom{\rule{4.pt}{0ex}}\mathrm{next}\phantom{\rule{4.pt}{0ex}}\mathrm{Direction},\hfill & \mathrm{Otherwise}.\hfill \end{array}\right.\end{array}$$
- If ${x}_{i,j}$ is not identified an edge in direction ${\mathit{\theta}}_{A}$, then the three other directions ${\mathit{\theta}}_{B}$, ${\mathit{\theta}}_{C}$ and ${\mathit{\theta}}_{D}$ are checked for an edge identification by applying the five steps above on each direction.

## 3. Illustration

- Sort all the pixels inside the selected patch in ascending order as $\mathbf{x}$ = [17 64 64 65 65 65 65 66 66 67 68 68 69 69 83 84 112 112 133 143 152 199 227 236 252].
- The extreme outliers are removed by using MAD given in Equation (3). The MAD value of vector $\mathbf{x}$ is 5, while the median value of $\mathbf{x}$ is 69. Therefore, according to the “Three Sigma Rule”, any value below 54 (69 − 15) and above 84 (69 + 15) is discarded and the vector $\mathbf{x}$ becomes [64 64 65 65 65 65 66 66 67 68 68 69 69 83 84].
- Next, the deference between every two consecutive pixels is found to be $\mathbf{d}$ = [0 0 0 0 1 0 1 1 0 1 0 14 2].
- The average value m of the vector $\mathbf{d}$ is equal to 1.4. Putting this value of m in Equation (5), ${\gamma}_{s}$ becomes 13.59.
- Using the separating threshold, all pixels of $\mathbf{x}$ are divided into groups as [64 64 65 65 65 65 66 66 67 68 68 69 69], [83 84].
- The largest group is [64 64 65 65 65 65 66 66 67 68 68 69 69], whose size is much greater compared to other group. Thus, this group is considered the clean group, while the other group is considered the noisy group.
- By employing Equation(9), any value greater than 69 and less than 63 is considered to be noisy.

## 4. Proposed Filtering Scheme

- If the size of ${\mathbf{g}}_{\mathbf{1}}$ is very large compared to the size of ${\mathbf{g}}_{\mathbf{2}}$ or R ≤ 0.5, then ${w}_{1}$ = 1, ${w}_{2}$ = 0.
- Similarly, when 0.5 $\le R\le $ 1, the assigned weights are: ${w}_{1}$ = 1, ${w}_{2}$ = 1.
- Finally, for 1 $\le R\le $ 2, the assigned weights are: ${w}_{1}$ = 1, ${w}_{2}$ = 2.

## 5. Summary of the Proposed Denoising Scheme

Algorithm 1: Proposed algorithm for random valued impulse noise removal. |

Input: The noisy image X, with size of ${L}_{1}\times {L}_{2}$1 Set iteration i = 1. 2 Outer loop: for ${l}_{1}=1,\dots {L}_{1}$, Inner loop: for ${l}_{2}=1,\dots {L}_{2}$ 3 Set a sliding window centered at ${x}_{i,j}$, the size of window is determined by $\sigma $. 4 Divide the window into groups of clean and noisy pixels using separating threshold computed in Equation (5). 5 Find mean $\mu $ and threshold $\gamma $ from clean cluster, while discard the noisy clusters. 6 Using Equation (7) check ${x}_{i,j}$ for noise. If $\mid \phantom{\rule{4pt}{0ex}}{x}_{i,j}-\mu \mid \le \gamma $, go to step (2). 7 If the pixel is identified as noisy, check ${x}_{i,j}$ for an edge using Equation (9). Such that if $\mathrm{std}(\mathbf{e},{x}_{i,j})\le \gamma $, go to step (2). 8 Filter ${x}_{i,j}$ as in Equation (11). 9 i = i + 1, if $i>{i}_{max}$, stop iteration, else X ⟵ Y, go to next iteration. Output: De-noised image Y |

## 6. Experimental Results

#### 6.1. Comparison of Noise Detection

#### 6.2. Comparison of Image Restoration

## 7. Conclusions

## Author Contributions

## Funding

## Conflicts of Interest

## References

- Gao, G.; Liu, Y.; Labate, D. A two-stage shearlet-based approach for the removal of random-valued impulse noise in images. J. Vis. Commun. Image Represent.
**2015**, 32, 83–94. [Google Scholar] [CrossRef] - Awad, A.S. Standard deviation for obtaining the optimal direction in the removal of impulse noise. IEEE Signal Process. Lett.
**2011**, 18, 407–410. [Google Scholar] [CrossRef] - Ilke, T. A new method to remove random-valued impulse noise in images. AEU-Int. J. Electron. Commun.
**2013**, 67, 771–779. [Google Scholar] - Chan, R.H.; Hu, C.; Nikolova, M. An iterative procedure for removing random-valued impulse noise. IEEE Signal Process. Lett.
**2004**, 11, 921–924. [Google Scholar] [CrossRef] - Jayasree, S.; Bodduna, K.; Pattnaik, P.K.; Siddavatam, R. An expeditious cum efficient algorithm for salt-and-pepper noise removal and edge-detail preservation using cardinal spline interpolation. J. Vis. Commun. Image Represent.
**2014**, 25, 1349–1365. [Google Scholar] [CrossRef] - Gonzalez, R.C.; Woods, R.E. Digital Image Processing; Prentice Hall: Upper Saddle River, NJ, USA, 2002. [Google Scholar]
- Astola, J.; Kuosmaneen, P. Fundamentals of Nonlinear Digital Filtering; CRC: BocaRaton, FL, USA, 1997. [Google Scholar]
- Singh, N.; Thilagavathy, T.; Lakshmipriya, R.T.; Umamaheswari, O. Some studies on detection and filtering algorithms for the removal of random valued impulse noise. IET Image Process.
**2017**, 11, 953–963. [Google Scholar] [CrossRef] - Chen, T.; Ma, K.; Chen, L. Tri-state median filter for image denoising. IEEE Trans. Image Process.
**1999**, 8, 1834–1838. [Google Scholar] [CrossRef] [PubMed] - Arce, G.R.; Paredes, J.L. Recursive weighted median filters admitting negative weights and their optimization. IEEE Trans. Signal Process.
**2000**, 48, 768–779. [Google Scholar] [CrossRef] - Ari, N.; Heinonen, P.; Neuvo, Y. A new class of detail-preserving filters for image processing. IEEE Trans. Pattern Anal. Mach. Intell.
**1987**, 1, 74–90. [Google Scholar] - Ko, S.-J.; Lee, Y.H. Center weighted median filters and their applications to image enhancement. IEEE Trans. Circuits Syst.
**1991**, 38, 984–993. [Google Scholar] [CrossRef] - Coyle, E.J.; Lin, J.; Gabbouj, M. Optimal stack filtering and the estimation and structural approaches to image processing. IEEE Trans. Acoust. Speech Signal Process.
**1989**, 37, 2037–2066. [Google Scholar] [CrossRef] - Vikas, G.; Chaurasia, V.; Shandilya, M. Random-valued impulse noise removal using adaptive dual threshold median filter. J. Vis. Commun. Image Represent.
**2015**, 26, 296–304. [Google Scholar] - Chen, T.; Hong, R.W. Adaptive impulse detection using center-weighted median filters. IEEE Signal Process. Lett.
**2001**, 8, 1–3. [Google Scholar] [CrossRef] - Lin, T.-C. Switching-based filter based on Dempster’s combination rule for image processing. Inf. Sci.
**2010**, 180, 4892–4908. [Google Scholar] [CrossRef] - Zhou, W.; Zhang, D. Progressive switching median filter for the removal of impulse noise from highly corrupted images. IEEE Trans. Circuits Syst. II Analog Digit. Signal Process.
**1999**, 46, 78–80. [Google Scholar] [CrossRef] - Luo, W. A new efficient impulse detection algorithm for the removal of impulse noise. IEICE Trans. Fund. Electron. Commun. Comput. Sci.
**2005**, 88, 2579–2586. [Google Scholar] [CrossRef] - Dong, Y.; Xu, S. A new directional weighted median filter for removal of random-valued impulse noise. IEEE Signal Process. Lett.
**2007**, 14, 193–196. [Google Scholar] [CrossRef] - Ghanekar, U.; Singh, A.K.; Pandey, R. A contrast enhancement-based filter forremoval of random valued impulse noise. IEEE Signal Process. Lett.
**2010**, 1, 47–50. [Google Scholar] - Bo, X.; Yin, Z. A universal denoising framework with a new impulse detector and nonlocal means. IEEE Trans. Image Process.
**2012**, 21, 1663–1675. [Google Scholar] - Antoni, B.; Coll, B.; Morel, J.-M. A non-local algorithm for image denoising. In Proceedings of the 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR’05), San Diego, CA, USA, 20–25 June 2005. [Google Scholar]
- Akkoul, S.; Ledee, R.; Leconge, R.; Harba, R. A new adaptive switching median filter. IEEE Signal Process. Lett.
**2010**, 17, 587–590. [Google Scholar] [CrossRef] - Johnstone, I.M.; Silverman, B.W. Wavelet threshold estimators for data with correlated noise. J. R. Stat. Soc. Ser. B (Stat. Methodol.)
**1997**, 59, 319–351. [Google Scholar] [CrossRef] - Cihan, T.; Akinlar, C. Edge drawing: a combined real-time edge and segment detector. J. Vis. Commun. Image Represent.
**2012**, 23, 862–872. [Google Scholar] - Chen, J.; Zhan, Y.; Cao, H.; Wu, X. Adaptive probability filter for removing salt and pepper noises. IET Image Process.
**2018**, 12, 863–871. [Google Scholar] [CrossRef] - Bovik, A.C. Handbook of Image and Video Processing; Academic Press: Cambridge, MA, USA, 2010. [Google Scholar]
- Lin, C.H.; Jia, S.T.; Ching, T.C. Switching bilateral filter with a texture/noise detector for universal noise removal. IEEE Signal Process. Soc.
**2010**, 19, 2307–2320. [Google Scholar]

**Figure 3.**Edges in different directions (

**a**) ${\mathit{\theta}}_{A}$; (

**b**) ${\mathit{\theta}}_{B}$; (

**c**) ${\mathit{\theta}}_{C}$; (

**d**) ${\mathit{\theta}}_{D}$.

**Figure 5.**Results of different filters in restoring $40\%$ corrupted Lena image: (

**a**) adaptive switching median filter (ASWM); (

**b**) tri-state median filter (TSM); (

**c**) progressive switching median filter (PSM); (

**d**) luo-iterative median filter (Luo); (

**e**) directional weighted median filter (DWM); (

**f**) Adaptive Switching Median Filter (ASWM); (

**g**) Switching Bilateral Filter (SBF); (

**h**) Robust Outlyingness Ratio Non-Local Mean (ROR-NLM); (

**i**) proposed method.

**Figure 6.**Results of different filters in restoring $60\%$ corrupted pepper image: (

**a**) adaptive switching median filter (ASWM); (

**b**) tri-state median filter (TSM); (

**c**) progressive switching median filter (PSM); (

**d**) luo-iterative median filter (Luo); (

**e**) directional weighted median filter (DWM); (

**f**) adaptive switching median filter (ASWM); (

**g**) switching bilateral filter (SBF); (

**h**) robust outlyingness ratio non-local mean (ROR-NLM); (

**i**) proposed method.

Methods | 40% | 50% | 60% | ||||||
---|---|---|---|---|---|---|---|---|---|

FN | FP | Total | FN | FP | Total | FN | FP | Total | |

ACWM | 14,590 | 2367 | 16,857 | 21,897 | 3706 | 25,603 | 30,198 | 6526 | 36,724 |

Luo’s | 14,679 | 1831 | 16,510 | 21,665 | 3068 | 24,733 | 33,987 | 2780 | 36,767 |

TSM | 18,921 | 5201 | 24,122 | 23,921 | 6218 | 30,139 | 28,123 | 8903 | 37,026 |

PSM | 18,672 | 4982 | 23,654 | 23,762 | 6123 | 29,885 | 27,987 | 8393 | 36,380 |

ASWM | 7489 | 11,564 | 19,053 | 11,779 | 12,786 | 24,565 | 19,982 | 16,482 | 36,464 |

DWM | 11,786 | 8931 | 20,717 | 15,321 | 8756 | 24,077 | 15,728 | 14,816 | 30,544 |

SD-OOD | 13,500 | 10,675 | 24,175 | 11,987 | 15,827 | 27,814 | 17,821 | 18,261 | 36,082 |

ROR-NLM | 12,890 | 3328 | 16,218 | 15,297 | 3487 | 18,784 | 21,827 | 7808 | 29,635 |

Propoposed | 10,908 | 7973 | 18,881 | 11,668 | 9613 | 21,241 | 13,571 | 9760 | 23,331 |

**Table 2.**Peak Signal-to-Noise Ratio (dB) values of different filters for Lena and Pepper image corrupted by random valued impulse noise of different noise densities.

Methods | Lena | Pepper | ||||
---|---|---|---|---|---|---|

(Noise Density) | 40% | 50% | 60% | 40% | 50% | 60% |

TSM | 24.91 | 22.22 | 18.98 | 24.02 | 22.56 | 17.78 |

ACWM | 28.12 | 24.64 | 20.32 | 28.12 | 26.09 | 21.52 |

LOU’S | 29.62 | 25.82 | 22.69 | 28.41 | 26.33 | 23.89 |

PSM | 29.12 | 25.31 | 24.23 | 28.23 | 25.41 | 23.83 |

ASWM | 30.91 | 28.42 | 26.25 | 29.02 | 27.12 | 25.33 |

DWM | 30.92 | 28.91 | 26.51 | 29.13 | 27.79 | 25.48 |

SBF | 30.12 | 27.12 | 23.13 | 28.89 | 27.02 | 24.67 |

ROR-NLM | 31.42 | 29.21 | 25.61 | 29.61 | 27.89 | 25.45 |

PROPOSED | 31.77 | 30.01 | 28.03 | 29.75 | 28.11 | 26.62 |

**Table 3.**Peak Signal -to- Noise Ratio (dB) values of different filters for Bridge and Boat image corrupted by random valued impulse noise of different noise densities.

Methods | Bridge | Boat | ||||
---|---|---|---|---|---|---|

(Noise Density) | 40% | 50% | 60% | 40% | 50% | 60% |

TSM | 21.55 | 19.72 | 17.26 | 22.89 | 20.72 | 17.55 |

ACWM | 23.72 | 22.19 | 19.12 | 25.32 | 23.56 | 21.45 |

LOU’S | 23.84 | 22.78 | 19.17 | 25.45 | 23.78 | 21.61 |

PSM | 23.65 | 21.91 | 19.39 | 24.98 | 22.98 | 20.87 |

ASWM | 24.02 | 22.69 | 21.12 | 26.76 | 25.26 | 23.23 |

DWM | 24.07 | 22.72 | 21.19 | 26.83 | 25.31 | 23.57 |

SBF | 22.12 | 21.31 | 20.15 | 25.33 | 24.88 | 22.67 |

ROR-NLM | 24.27 | 22.91 | 21.21 | 27.23 | 25.43 | 24.21 |

PROPOSED | 24.35 | 23.08 | 21.75 | 27.85 | 26.61 | 24.87 |

© 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Iqbal, N.; Ali, S.; Khan, I.; Lee, B.M.
Adaptive Edge Preserving Weighted Mean Filter for Removing Random-Valued Impulse Noise. *Symmetry* **2019**, *11*, 395.
https://doi.org/10.3390/sym11030395

**AMA Style**

Iqbal N, Ali S, Khan I, Lee BM.
Adaptive Edge Preserving Weighted Mean Filter for Removing Random-Valued Impulse Noise. *Symmetry*. 2019; 11(3):395.
https://doi.org/10.3390/sym11030395

**Chicago/Turabian Style**

Iqbal, Nasar, Sadiq Ali, Imran Khan, and Byung Moo Lee.
2019. "Adaptive Edge Preserving Weighted Mean Filter for Removing Random-Valued Impulse Noise" *Symmetry* 11, no. 3: 395.
https://doi.org/10.3390/sym11030395