A New Method for Adaptive Filtering of Images

Pavel A. Lyakhov1, Anzor R. Orazaev2, Dmitrii I. Kaplun4 Nikolay I. Chervyakov3 Department of Automation and Control Processes Department of Applied Mathematics and Mathematical Saint-Petersburg Electrotechnical University "LETI" Modeling, St. Petersburg, Russia North-Caucasus Federal University [email protected] Stavropol, Russia [email protected], [email protected], [email protected]

Abstract — A new method of adaptive median filtering of large size with processing the result of median filtering based impulse in images is proposed in this paper. The method is on the Lorentz distribution was proposed in [8]. based on the combined using of iterative image processing and post-processing of the median filtering result. The results of a In this paper we propose a new approach to adaptive comparison of the quality of the proposed method with known median image filtering, which uses iterative image processing methods are shown in the experimental part of the article. The with small-size masks and post-processing of the median simulation results showed that the proposed method performs filtering result. We will show the results of applying the better then known methods in all cases. The results obtained in proposed method for image processing distorted by impulse the paper can find wide practical application in the processing of noise with an intensity of up to 99%. satellite and medical images, geophysical data and other applications of . The main content of the paper is organized as follows. The existing methods of adaptive median filtering are given in Keywords — digital image processing; impulse noise; median Section II. In Section III we present the proposed method. filter; adaptive filter. Section IV compares the performance of the proposed method with known approaches, with a discussion of the data obtained. I. INTRODUCTION Digital images are exposed to noise when received or II. ADAPTIVE MEDIAN FILTERING OF IMAGES transmitted, which leads to a deterioration in visual quality and We assume that digital images are represented by a set of loss of image areas. The task of repairing damaged pixels pixels with intensity values x , where the coordinates (i, j) before the main processing is an important task of digital image i, j processing [1, 2]. Currently there are a large number of image change over a subset of the set Z 2 , where Z is the set of de-noising methods, depending on the type of noise exposure. integers. For simplicity of description, we will consider In this paper, we consider methods of impulse noise removing. grayscale images, in which the intensity values are encoded with 8-bit numbers and change from 0 (black color) to 255 The image distorted by impulse noise looks with white and (white color). black pixels randomly scattered across the frame. The best method for removing impulse noise is median filtering, which At present, several models of impulse noise are known, replaces the pixels of the image with the corresponding median which are presented, for example, in [7]. The difference values of some neighborhood [3]. However, median filters lead between these models is important only when establishing the to blurring of the image. This becomes especially noticeable fact of the presence of in the pixel of the image. We when processing images distorted by impulse noise with high confine ourselves to the simplest model, in which impulse intensity. Approaches based on adaptive filtering have been noise refers to the distortion of a signal by impulses with very proposed in [4, 5] to reduce this negative effect. large positive or negative values and a short duration. Under the influence of this noise on an 8-bit grayscale image, each With adaptive median filtering, the fact of the presence of p impulse distortion of a pixel is first established, after which it is pixel (independently of the others) with probability is corrected. Very effective methods for determining pixels converted into one of two fixed values: 0 or 255. If we denote distorted by impulse noise are proposed in [6, 7]. Currently, by xi, j the intensity values of the pixels of the distorted image, there are different approaches to correcting pixels distorted by then the probability density function of the impulse noise f ()x impulse noise. Method proposed in [5] is based on increasing is given by the expression the mask of the median filter until an acceptable result value is obtained. Iterative correction of distorted pixels by a square 3×3 mask is prosed in [4]. A method using square masks of

1197 978-1-7281-0339-6/19/$31.00 ©2019 IEEE

= III. PROPOSED METHOD OF ITERATIVE ADAPTIVE MEDIAN  px0,,where ij 0; =−− < < FILTERING fx() 1 p0 p 255 ,where 0 xij , 255; (1)  = Let {{y(0)},{y(1)},...,{y(n) )},...} is a sequence of grayscale  px255,where ij , 255, i, j i, j i, j (0) (1) (n) where p0 is the probability of pixel distortion by value 0, images and {{gi, j },{gi, j},...,{gi, j },...} is a sequence of () p255 is the probability of pixel distortion by value 255 and n maps of distorted pixels in which the values gi, j are p + p = p . 0 255 determined depending on the presence of distortion in the () The simplest for cleaning images from pixel y n as follows: impulse noise is the standard median filter (SMF) [3]. Filtering i, j () using SMF is performed by moving the filter mask along a 0, ify n is not distorted; ()n =  ij, sequence of discrete samples with assigning the median of the gij,  () (2) 1, ify n is ditorted. array of values within the mask to the resulting signal sample.  ij, Since the SMF processes all the pixels, the image details are (0) We use the notation {y } for the original noisy image. also deleted in addition to noise. Various approaches have been i, j proposed for eliminating the shortcomings of the SMF, which (n) {yi, j } is denotes the value of a pixel with coordinates (i, j) can be divided into two main groups: weighted median filters (WMF) and adaptive median filters [9]. The WMF uses after the n-th iteration of the method. In the sequence of maps (n) (n) = weights (usually for a central pixel) that show the contribution of distorted pixels {gi, j } the value gi, j 0 is means that a of each pixel to an ordered array of values [10-12]. However, pixel with coordinates ()i, j is not distorted, and the value the weighted median filtering is performed over all pixels in the image (just like the SMF). (n) = () gi, j 1 is means that a pixel with coordinates i, j is «Adaptive median filters» are a common name for a group distorted and needs to be fixed. According to the model (1), if of filters that process only those pixels of the image in which (0) (0) (0) y = 0 or y = 255 then the initial values of g are set impulse distortion is present, and undistorted pixels remain i, j i, j i, j unchanged. In accordance with the model of impulse noise (1), equal to 1, and if 0 < y(0) < 255 then the initial values of g (0) we will consider that pixels with values of 0 or 255 are i, j i, j distorted, and all others are undistorted. are set equal to 0. In paper [5] an adaptive median filter is proposed, which i −1, j assumes an increase in the size of the processed neighborhood i, j −1 i, j i, j + 1 when a distorted pixel is detected. The process is repeated until i + 1, j either a median is found that is different from the impulse value, or the dimensions of the neighborhood do not reach the Fig. 1. Filter mask in the proposed method maximum allowed size. This method shows good practical = (n−1) = results for noise with low probability p , while for high values At the n-th iteration ( n 1, 2,... ) for each gi, j 0 the p it loses the ability to correct . (n) = (n−1) (n−1) = assignment yi, j yi, j is performed. For each gi, j 1, an The method from [4] assumes iterative performance of the array M is formed as follows. The set of pixels with median filtering operations with a filter 3× 3 mask. An coordinates important feature of this method is finding the median of an A = {()()()()}i −1, j , i, j −1 i, j +1 , i +1, j (3) array composed of only undistorted pixels. If all the pixels are is viewed (Fig. 1). The mask shown in Fig. 1, is a set of pixels × distorted in the window 3 3 (which is very likely for high whose coordinates are spaced from the central pixel by a values of p ), then the pixel is not considered as corrected. If distance no greater than 1 in the sense of the Euclidean metric some pixels remain distorted as a result of image processing, L2 . If some of the elements in the set A take invalid values then the result should be processed again, and so on until all the (are outside the boundaries of the image) then for the pixels become corrected. corresponding coordinates in the array M is added nothing. The authors of [8] propose using a square mask with a size For the remaining elements of the set A the value with the ()− depending on the probability p . As in the method of [4], only corresponding coordinate in the map g n 1 is checked. If it is undistorted pixel values are selected to find the median in the equal to 1 then nothing is added to the array M . If it is equal ordered array. However, the median found is not assigned as a to 0 then an element mk which is equal to the value of the corrected pixel value, but is used to estimate it based on the ()n−1 Lorentz distribution. pixel with the corresponding coordinate from the image y , is added to the array M . If array M remained empty after viewing all the elements of the set A then is necessary to (n) = () assign gi, j 1 (meaning that a pixel with coordinates i, j

1198 remained distorted). If there is at least one element in array probabilities p = 0.01;0.1;0.25;0.5;0.75;0.9;0.99 by using the M , then is necessary to find its median median ()M , and also "imnoise" command with default parameters from the (n) = software package MATLab 2015b. This means that the assign gi, j 0 . Further, for array M it is necessary to = impulse noise model (1) was used, in which po p255 i.e. the (n) = calculate the value yi, j and assign it to a pixel yi, j . impulse noise was bipolar [1]. We used the value r 180 when performing calculations using (5). The value of yi, j is calculated as follows. Suppose that The peak signal-to-noise ratio (PSNR) was used for when processing a distorted pixel xi, j by the mask of the filter evaluation the quality of image cleaning from noise, which is an array M consisting of undistorted pixels mk was formed. calculated by the formula: We denote by medianM the median of the array M . For PSNR= 10lg() R2 MSE , (8) each pixel m we calculate the value k where d = m − medianM . (4) 2 k k MSE=−⋅() y s D D (9) ψ  ij,, ij 12 For each dk we find the value of the function ()dk by the ij formula is mean square error of the reconstructed image yi, j in <−  0, ifdrk 2 ; comparison with the original image si, j ; R is the maximum −− − ≤ <− 2,if2rdkk r d r ;  value of the image pixel, equal to 255 in the cases under ψ =−≤≤ (5) ()ddkk , if rdr k ; consideration; D1 and D2 are width and height of the image,  2,if2;rd−<≤ r d r respectively. The PSNR value has logarithmic nature and its  kk < unit of measurement is decibel (dB). The larger PSNR value  0, if 2rdk . means the better quality of the reconstructed image and where r is the level of rejection, depending on the variance of PSNR =∞ for identically equal images. the image. The corrected pixel value yi, j is assigned the Structural SIMilarity (SSIM) between two images, which value is determined on the basis of a complete comparison of the = ()ψψ() original and obtained images [13]. SSIM is calculated by the ymddddij,  k() k k () k k . (6) kk formula: The procedure stops after N -th iteration, on which there (2μ μ + c )(2σ + c ) SSIM ( y, s) = y s 1 ys 2 (10) are no distorted pixels, that is μ 2 + μ 2 + σ 2 + σ 2 + ( y s c1 )( y s c2 ) (N ) g = 0 . (7) 2  i, j where μ is mean of y , μ is mean of s , σ is variance ij y s y

(N) of y , σ 2 is variance of s , σ is covariance of y and s , Image {yi } is considered as denoised output image. s ys = 2 = 2 Next, the results of simulation of image cleaning from ckR11(), ckR22() are two variables, R is dynamic impulse noise using the proposed method will be presented range of pixels equal to 255 in the cases under consideration, = = and a comparison with the results obtained using known k1 0.01 and k2 0.03 are constants. The value of SSIM is methods will be made. located between 0 and 1 and SSIM is equal to 1 for identically equal images. IV. SIMULATION RESULTS We used the standard Lena image with 512× 512 pixels for modeling. The image was distorted by impulse noise with

TABLE I. PSNR VALUES FOR THE RESULTS OF LENA IMAGE CLEANING BY VARIOUS METHODS.

Known methods p Proposed method [3] [5] [8] [4] 0.01 34.47 52.07 53.19 53.06 53.74 0.10 32.52 40.18 42.40 42.24 43.32 0.25 26.02 33.63 35.84 37.47 38.31 0.50 15.25 28.09 30.83 32.75 33.12 0.75 9.03 19.01 28.09 29.07 29.07 0.90 6.63 10.50 24.22 25.68 25.77 0.99 5.53 5.91 16.28 19.91 19.88

1199

TABLE II. SSIM VALUES FOR THE RESULTS OF LENA IMAGE CLEANING BY VARIOUS METHODS.

Known methods p Proposed method [3] [5] [8] [4] 0.01 0.9261 0.9990 0.9992 0.9991 0.9994 0.10 0.9123 0.9881 0.9912 0.9908 0.9933 0.25 0.7968 0.9568 0.9637 0.9737 0.9795 0.50 0.2293 0.8758 0.9046 0.9327 0.9401 0.75 0.0340 0.5510 0.8335 0.8625 0.8658 0.90 0.0111 0.0710 0.7145 0.7598 0.7617 0.99 0.0064 0.0065 0.4632 0.5617 0.5634

a) b) c)

d) e)

f) g)

Fig. 2. a) The original grayscale image Lena; b) image distorted by impulse noise with intensity p = 0.9 ; c) result of applying the method from [3]; d) result of applying the method from [5]; e) result of applying the method from [8]; f) result of applying the method from [4]; g) result of applying the proposed method.

Tables 1-2 show the results of cleaning the test image from V. CONCLUSIONS impulse noise with varying intensity. It can be seen that the best results were obtained using the proposed method. Figure 2 A new method for cleaning images from impulse noise is shows the results of processing the Lena image, distorted by proposed, which allows improving the quality of processing, in = comparison with known approaches. Numerical evaluation of impulse noise with p 0.9 . The visual quality of the images simulation results based on PSNR and SSIM allows to in Figure 2 confirms the high quality of the processing results conclude that proposed method better clears images from both by the proposed method.

1200 noise with low intensity, and from extreme with an [5] H. Hwang and R.A. Haddad, “Adaptive median filters: new algorithms intensity of 90%-99%. The obtained result allows to solve the and results,” IEEE Transactions on Image Processing, vol. 4, 1995, pp. problem of impulse noise cleaning with higher efficiency. 499–502. [6] A. Fabijańska and D. Sankowski, “Noise adaptive switching median- An interesting direction of further research is the based filter for impulse noise removal from extremely corrupted application of the proposed method in practical applications of images,” IET image processing, vol. 5, no. 5, 2011, pp. 472-480. digital image processing, for example, for processing visual [7] P.E. Ng and K.K. Ma, “A switching median filter with boundary discriminative noise detection for extremely corrupted images,” IEEE data in medical diagnostics. Transactions and Image Processing, vol. 15, no. 6, 2006, pp. 1506– 1516. ACKNOWLEDGEMENTS [8] V.R. Vijaykumar and D. Ebenezer, “High Density Impulse Noise This work was supported by the Government of the Russian Removal Using Robust Estimation Based Filter,” IAENG International Federation (state order no. 2.6035.2017/BCh), the Russian Journal of Computer Science, vol. 35, no. 3, 2008. Foundation for Basic Research (projects no. 18-07-00109 A [9] K.S. Srinivasan and D. Ebenezer, “A New Fast and Efficient Decision- and no. 18-37-20059 mol-a-ved), and by the Presidential Grant Based Algorithm for Removal of High-Density Impulse Noises,” IEEE letters, vol. 14, no. 3, 2007. of the Russian Federation (project no. SP-2245.2018.5). [10] D. Brownrigg, “The weighted median filter,” Communications of the ACM, vol. 27, no. 8, 1984, pp. 807–818. REFERENCES [11] L. Yin, R. Yang, M. Gabbouj, and Y. Neuvo, “Weighted median filters: [1] R.C. Gonzalez and R.E. Woods, Digital Image Processing, 3rd edition. a tutorial,” IEEE Transactions on Circuits and Systems II: Analog and Pearson, 2007. Digital Signal Processing, vol. 43, no. 3, 1996, pp. 157–192. [2] R.C. Gonzalez, S.L. Eddins, and R.E. Woods, Digital Image Processing [12] N.I. Chervyakov, P.A. Lyakhov, A.R. Orazaev, and M.V. Valueva, using MATLAB, Morphological reconstruction. MathWorks, 2010. “Efficiency analysis of the image impulse noise cleaning using median [3] J.W. Tukey, Exploratory data analysis. Pearson, 1977. filters with weighted central element,” 2017 International Multi- [4] Z. Wang and D. Zhang, “Progressive switching median filter for the Conference on Engineering, Computer and Information Sciences removal of impulse noise from highly corrupted images,” IEEE (SIBIRCON), 2017, pp. 141-146. Transactions on Circuits and Systems II, 1999, pp. 78–80. [13] Z. Wang, “Image quality assessment: from error visibility to structural similarity,” IEEE Transactions on image processing, vol. 13, no. 4, 2004, pp. 600-612.

1201