Keywords

4.1 Introduction

Digital image plays an important role in many fields of science and technology, such as bioengineering, medicine, defect detection, face recognition, industrial size detection, etc. Size detection is an effective noncontact detection technology. It has been widely applied in on line detection of various kinds of artifacts. Impulsive noises can be commonly found in the sensor or transmission channel during acquisition and transfer procedures for digital signal images. Salt-and-pepper noise [1, 2] is one typical kind of impulsive noise. Factors of salt-and-pepper noise mainly include sensor and digital image equipment, electrical system factors, environmental factors in the process of image generation, etc. So it must process the noise of image; its objective is to improve the image quality and signal-to-noise ratio, and reduce the influence of image noise on the final measurement results. In order to reduce noise and not to make it fuzzy, the image must be filtered. Nonlinear filtering algorithm represented by median filter uses statistical properties of the sort of image and it is better to keep the image details. However, the median filter basically does not work when density is greater than 0.5. In order to solve this problem, some improved median filter algorithms have been proposed such as weighted median filter [3], adaptive median filter, etc. However, these algorithms treat all pixels equally, as a result these noise-free pixels could be altered sometimes. In this paper, an improved adaptive filter algorithm is proposed based on threshold. The improved adaptive filter algorithm can not only get rid of the noise with high density, but also keeps the details of the image.

4.2 The Basic Principle of Median Filter Algorithm

Median filter is nonlinear filtering technique based on the theory of order statistics [4, 5]. It was established in 1971 by Turky. Median filter, the most prominently used impulse noise removing filter, provides a better way of removal of impulse noise from corrupted images by replacing every pixel of the image by the median value of the pixels from a neighborhood chosen around the corresponding pixel. Median filtering can not only effectively remove the noise of the isolated points, but can also overcome the image detail fuzzy problem [6].

Median filter is defined as follows:

Let \( x_{1} ,x_{2} , \ldots ,x_{n} \) be an array. The array is arranged in ascending order.

$$ y = {\text{med}}(x_{1} ,x_{2} , \ldots ,x_{n} ) = \left\{ {\begin{array}{*{20}c} {x_{i(n + 1/2)} } & {n\,{\text{is}}\,{\text{odd}}} \\ {\frac{1}{2}\left[ {x_{{^{i(n + 1/2)} }} + x_{i(n/2 + 1)} } \right]} & {{\text{even}}\,n} \\ \end{array} } \right. $$
(4.1)

where y is a median of array.

In the one-dimensional case, the median filter is a sliding window with odd pixels. The pixel value of the window center is replaced by the median of the window pixels. In the two-dimensional case, it chooses some form of two-dimensional sliding window, and then the pixel gray values are arranged in ascending order. The output of filter is

$$ y_{ij} = {\text{med}}(x_{ij} ) = {\text{med}}\left\{ {x_{(i + r)(j + s)} } \right\} $$
(4.2)

Here \( r,s \) belongs to the two-dimensional filtering window and \( {\text{med}} \) is a median in an array.

Two-dimensional median filters have many different window shapes and different shapes have different filtering effects. The filtering effect is not ideal if the template is too small. It may result in the loss of boundary information if the template is too large and the image processing speed is slow because of increasing computational complexity. According to the contents and requirements of the image, it should select the appropriate window shape. In addition, the sparse distribution template saves time.

As a nonlinear filtering technique, median filter replaces the value of pixel by the median of the gray levels in the neighborhood of that pixel. The median filter not only removes noise, but also well protects the edge of the image and sharpens the detail. But the median filter changes the gray value of the image to a certain extent. Sometimes, it loses details and small target areas of the image and requires a lot of sorting operation.

4.3 The Adaptive Median Filter Algorithm Based on Threshold

4.3.1 Adaptive Median Filter Algorithm

The center pixel value is replaced by the median of the window gray levels. It is easy to filter some detailed information. In addition, it is invalid when the noise number is greater than the half the window size. To remedy these shortcomings mentioned above, it must increase the filtering window so that the image details are preserved. In adaptive median filtering algorithm [7, 8], first, all the pixels are separated into signal pixels and noise pixels. Then it processes noise and signal points by different processing methods. It removes the noise by changing the size of the filter window. Adaptive median filter algorithm gets a single value by changing the size of the window in denoising process. The single value is used to replace the center pixel value of the window.

For a size \( M \times N \) of the image, let \( S_{xy} \) be the filter window of a true image at pixel location (x, y), f(x, y) be the gray level at pixel location (x, y), \( S_{ \hbox{max} } \) be the largest filter window, \( f_{ \hbox{min} } \) be the minimum gray value, \( f_{ \hbox{max} } \) be the maximum gray value, \( f_{\text{med}} \) be the median of the filter window. The steps of the adaptive median filter algorithm are elucidated as follows:

  1. Step 1:

    Set initialize filter window size \( w = 3 \).

  2. Step 2:

    Compute the minimum value \( f_{ \hbox{min} } \), the maximum value \( f_{ \hbox{max} } \), and the median value \( f_{\text{med}} \) of the current window pixel.

  3. Step 3:

    If \( f_{ \hbox{min} } < f_{\text{med}} < f_{ \hbox{max} } \), then go to Step 5. Otherwise increase the window size by 2.

  4. Step 4:

    If \( w \le S_{ \hbox{max} } \), then go to Step 2. Otherwise it is considered as corrupted pixel and replace by \( f_{\text{med}} \).

  5. Step 5:

    If \( f_{ \hbox{min} } < f\left( {x,y} \right) < f_{ \hbox{max} } \), then it is considered as uncorrupted pixel and is retained. Otherwise it is considered as corrupted pixel and replace by \( f_{\text{med}} \).

4.3.2 Improved Adaptive Median Filter Algorithm

The adaptive median filter is effective to smooth the image of the salt-and-pepper and maintains excellent image edge and detail information. But with increase in noise density, adaptive median filter is not satisfactory. From the adaptive median filtering steps, it judges noise and signal point, which are based on the minimum and maximum values. It is easy to cause an edge or the high frequency part of the miscarriage of justice. Thus it is not good to keep image edge details.

In order to keep the image edge and texture details, it must distinguish the noise points and signal points before the filtering process. In this paper an adaptive median filter algorithm based on threshold [9] is proposed. In the polluted area, the difference in the gray value between noise pixels and other pixels in the window is larger. In the unpolluted area, however, the difference in the gray value between noise pixels and other pixels in the window is smaller. So the variable threshold with the change of the template window is adopted. The threshold could be obtained adaptively in each window.

The concrete implementation process of the dynamic threshold is elucidated as follows:

  1. 1.

    Compute the mean and standard except the center pixel in the template window.

    $$ f_{{{\text{ave}}}} = \sum\limits_{{i = 1}}^{n} {f\left( {x,y} \right)/n} $$
    (4.3)
    $$ f_{{{\text{var}}}} = \sqrt {\sum\limits_{{i = 1}}^{n} {\left( {f\left( {x,y} \right) - f_{{{\text{ave}}}} } \right)^{2} /n} } $$
    (4.4)
  2. 2.

    The center pixel is subtracted from the other pixels in the template window and takes the absolute value \( \left| {\Delta f(i)} \right|,i = 1,2, \ldots n \).

  3. 3.

    Compute \( F_{1} \), \( F_{2} \).

    $$ F_{1} = \frac{1}{n}\sum\limits_{i = 1}^{n} {\left| {\Delta f\left( i \right)} \right|} $$
    (4.5)
  4. 4.

    Compute threshold \( T \).

    $$ T = \left( {F_{1} + F_{2} } \right) \times \frac{{f_{\text{ave}} }}{{f_{\text{ave}} + f_{\text{var}} }} $$
    (4.6)

This kind of dynamic threshold method and adaptive median filtering method combine to form an improved adaptive median filter algorithm. The steps of the adaptive median filter algorithm based on dynamic threshold are elucidated as follows:

  1. Step 1:

    Set initial filter window size \( w = 3 \).

  2. Step 2:

    Compute the minimum value \( f_{ \hbox{min} } \) and the maximum value \( f_{ \hbox{max} } \) of the current window pixels. If \( f_{ \hbox{max} } - f_{ \hbox{min} } > T \) (\( T \) is threshold), then go to step 3. Otherwise move to the next pixel and go to Step 1.

  3. Step 3:

    Find out all pixel values between \( f_{ \hbox{max} } \) and \( f_{ \hbox{min} } \) of the window. Let \( n \) be the number of finding all pixels values. If \( n \ge w \), compute the median of these pixels. If \( n < w \), increase the window size by 2 and go to Step 1.

  4. Step 4:

    If the current pixel \( f(x,y) = f_{ \hbox{max} } ||f(x,y) = f_{ \hbox{min} } \), then it is considered as corrupted pixel and replace by \( f_{\text{med}} \). Otherwise it is retained, and go to Step 1.

4.4 Experimental Results and Analysis

To validate the efficiency of the proposed method, we adopt the \( 512 \times 512 \) standard Lena gray image as the test image based on MATLAB R2008a. Let \( 7 \times 7 \) is the largest template window. Images are corrupted by salt-and-pepper noise at various noise densities. The results are shown in Figs. 4.1 and 4.2. Figure 4.1 shows the restoration results using various filters for image Lena corrupted by 10 % random-value noise. Figure 4.2 shows the restoration results using various filters for image Lena corrupted by 70 % random-value noise.

Fig. 4.1
figure 1

Restoration results using various filters for image Lena corrupted by 10 % random-value noise. a Original image. b Corrupted image. c 3 * 3 Median filter. d 5 * 5 Median filter. e Adaptive median filter. f Improved adaptive median filter

Fig. 4.2
figure 2

Restoration results using various filters for image Lena corrupted by 10 % random-value noise. a Original image. b Corrupted image. c 3 * 3 Median filter. d 5 * 5 Median filter. e Adaptive median filter. f Improved adaptive median filter

From Fig. 4.1c–f, both the adaptive median filter and improved adaptive median filter not only remove the noise, but also can preserve the edge and detail information about the image when the noise density is small. The \( 3 \times 3 \) median filter is good to maintain the image details, but it is obvious that Fig. 4.1c still has a very small amount of noise. The \( 5 \times 5 \) median filter blurs a few details. From Fig. 4.2c–e, the median filtering algorithm is basically a failure and removing noise effect is not ideal by adaptive median filter. From Fig. 4.2f, the Lena image filtered by improved adaptive median filter algorithm proposed in this paper has better image quality than those by other methods. The image edge and detailed information is preserved well and the noise is basically removed. Finally, we can draw the conclusion that the proposed method can give better visual effect of noise restoration than adaptive median filter when the noise density is larger.

From the image point of view, with the increase in noise density, image clarity is reduced after adaptive median filter. However, the image is still relatively clear by improved adaptive median filter.

In order to evaluate the effect of filter algorithm, the peak signal noise ratio (PSNR) [10, 11] is used as the objective evaluation parameters. While its value is greater, the effect of denoising is better. It is often used in image processing, especially in image denoising. The obtained PSNR is shown in Table 4.1.

Table 4.1 Comparison of PSNR values of different algorithm for image at different noise densities

From Table 4.1, we can see that the PSNR of the improved adaptive median filter algorithm is bigger than the adaptive median filter and median filter when the noise density is the same. The PSNR moderating trend of the median filter is larger with the increase in noise density. The PSNR moderating trend of adaptive median filter algorithm and improved adaptive median filter algorithm is resembled. But the PSNR value of the improved adaptive median filter is higher than adaptive median filter in the same high density. From Table 4.1 it is seen that the improved adaptive median filter algorithm is effective for high density noise removal.

4.5 Conclusion

In this paper an improved adaptive median filter for edge and detail information preservation is proposed. The median filter and adaptive median filter fail to preserve the necessary details when noise level is bigger. With the increase in noise density, improved adaptive median filter algorithm gives better performance in comparison with all the discussed algorithms in this paper. The improved adaptive median filter not only removes the high density noise of the image, but also protects more image details and information. Experimental results show that the improved adaptive median filter improves the accuracy of noise and the fidelity of image filtering, and has better performance on the high density noise.