Switching median filter for suppressing multi-pixel impulse noise

This paper proposes a new switching median filter for suppressing multi-pixel impulse noise in X-ray images. A multi-pixel impulse is understood as a set of several neighboring pixels, the intensity of each significantly exceeds background intensity. Multi-pixel noise can occur, for example, due to the blooming effect, the reason being the limited value of pixel saturation capacity. This article defines the thresholds for the intensity increment relative to the eight immediate neighbors, above which the current pixel is processed by the median filter. The dependence of these thresholds on the number of pixels in an impulse is presented. The proposed algorithm is based on the median filtering process, which consists of several iterations. In this case, the filter has the smallest possible size, which minimizes image distortion during processing. In particular, to exclude a single-pixel impulse, pixel processing is turned on when intensity surge exceeds 3.5 with the grayscale value ranging from 0 to 1. At the same time, to exclude nine-pixel impulses, three iterations are required with the following thresholds: the first iteration with a threshold 2.0; the second iteration also with a threshold 2.0 and the third iteration with a threshold 3.5. The algorithm proposed was tested on real X-ray images corrupted by multi-pixel impulse noise. The algorithm is not only simple, but also reliable and suitable for real-time implementation and application. The efficiency of the technique is shown in comparison with other known filtering methods with respect to the degree of noise suppression. The main result of the testing is that only the proposed method allows excluding multi-pixel noise. Other advantage of the algorithm is its weak effect on the level of Gaussian noise leading to the absence of image blurring (or preserving image details) during processing.


Introduction
An important area of computer vision includes image filtering techniques. Among software developers, the socalled spatial filtering methods are very popular when image processing as a two-dimensional signal in x0y space of its recording is carried out [1].
Spatial filtering methods include linear averaging filtering techniques, image sharpening, median (nonlinear) filtering techniques and some others. Linear averaging filtering process is an operation of averaging weighted intensities of neighbors being the closest to the pixel processed with the aim to smooth out Gaussian noises. Image sharpening can be achieved applying differentiation operators, in particular, adding the Laplacian image to the original one. In median filtering, during which the smoothed value of pixel intensity is taken equal to the median intensity value of the pixels in immediate neighborhood, impulse noise is eliminated. The characteristic features of each spatial filtering method can be most clearly demonstrated when processing small image templates. In fig. 1a, a template of n x × n y = 50 × 50 pixels in size containing three rows of maximum intensity fragments on grey background with half of maximum intensity is presented. Here, n x and n y are the number of pixels along two spatial axes. The first line of the template contains three intensity fragments consisting of 1, 2 and 3 pixels, respectively, the second line contains three intensity fragments consisting of 4, 5 and 9 pixels, the third line contains two square fragments consisting of 16 and 25 pixels. Fig. 1b shows a template image after linear averaging filtering with a 3 × 3 mask. Fig. 1c shows the result of processing the template with a Laplacian-based differential operator. And finally, fig. 1d -f illustrate the results of median filtering of the template for various sizes of a filter window. The analysis of template processing given in fig. 1 shows that if an image sharpening filter mainly solves the task of highlighting transitions in intensity (see fig. 1c), linear averaging and median filters in addition to performing the functions assigned to them lead to artifacts. Averaging filter leads to image blur (see fig. 1b), and median filter rounds off the corners of image fragments also blurring the image, the larger size of a filter window, the higher degree of such image distortions (see fig. 1d -f).
To minimize these distortions adaptive filtering techniques are used [2].
Moreover, these techniques do not produce pleasing performance in terms of suppression of multi-pixel impulse noise, which is the result of various physical phenomena during recording X-ray images. To solve this problem a new method is proposed in this paper.

Related work
The subject of research in this article is a switching median filter. Switching filters are one of the types of adaptive filters.
The switching median filtering process consists of two steps: at the first step, image pixels corrupted by impulse noise are detected, and then such pixels are corrected by a standard median filter.
The paper [3] proposes an iterative correction of corrupted pixels using 3 × 3 filtering window with subsequent exception of corrupted pixels from processing. This idea was developed in [4] where additional processing of pixels based on fuzzy sets was proposed. Another modification of the method [3] is the use of windows of other sizes being determined after the analysis of the image processed [5]. In [6], a method based on nonlinear processing of median filtering result using the Lorentz distribution was proposed.
In [7], the authors propose an adaptive median filter which implies the increase in the size of the immediate neighborhood processed when a corrupted pixel is detected. The process is repeated until either a median other than impulse value is found or the size of the neighborhood reaches the maximum allowed size. This method shows good practical results for noise with a low probability, while for high values of probability it loses the ability to correct corruptions.
In [8], an algorithm for the detection of impulse noise based on the analysis of β increment intensity in each (i, j) pixel relative to immediate N-1 neighbors was proposed where G ij is the intensity of noisy image pixel at location (i, j), G mn is the intensities of the pixels in immediate neighborhood centered around the current pixel (i, j), K is an odd number, N = K × K is the size of a filter window. If the value of parameter β ij is small, then the pixel at location (i, j) is considered as uncorrupted one. According to the results of experiments, for 8-bit monochrome images with intensity range for shades of gray from 0 to 255, threshold value of parameter β being determined in [8] is 90 at N = 9. A powerful impulse noise detection method called boundary discriminative noise detection (BDND) is proposed in [9]. To determine the fact of each pixel being corrupted by impulse noise, the method classifies all pixels into three groups: impulse noise of small intensity ("pepper"), uncorrupted pixel and impulse noise of high intensity ("salt"). The basis of the algorithm is to determine two boundaries of three indicated groups being found as maximum intensity differences of two neighboring pixels located before and after the median value of immediate neighborhood of 21 × 21 size centered around the current pixel. One often quoted study [10] proposes an effective method for detecting pulsed noise. Let's consider this algorithm in detail.
In the detection stage, a pixel in corrupted image G ij is considered noisy if two conditions are satisfied.
The first condition is for preliminary classification of all pixels in the image   where M is intensity interval within which pixel (i, j) is considered corrupted.
The second condition allows us to further classify the pixels being corrupted after the first classification    (4) where N 1 is the number of pixels falling into a sliding window N = 3 × 3 with a central (i, j) pixel (CP) for which 0 ≤ G ij ≤ M; N 2 is the number of pixels in the window for which 255 -M ≤ G ij ≤ 255; α 1 = N (p 1 + 0.5), α 2 = N (p 2 + 0.5), density (probability) of noise pulses p 1 = K 1 / (n x × n y ), p 2 = K 2 / (n x × n y ); K 1 , K 2 is the number of "dark" and "bright" impulses in the image, respectively.
An analysis of test image filtering results obtained using these techniques allowed us to conclude that MOD algorithm demonstrates the best detecting characteristics.
MOD algorithm is a sequence of calculation steps. The size N = K × K of a sliding window is set first.
Then mean , standard deviation σ, quartiles Q 1 and Q 3 , and inter-quartile range IQR = Q 3 -Q 1 of all pixels of a sliding window except CP are calculated.
Consequently, the first level of thresholds is defined as follows: the second level of thresholds is defined as follows: Then they verify whether and If the above conditions (7,8) are satisfied, CP at location (i, j) is noisy.
However, if they verify whether and again (8).
Otherwise, CP is noise-free. Corrupted pixels are processed by median filter.
In conclusion of the introductory part of the paper, we should emphasize that all the algorithms described above are intended and are effective for impulses consisting of one pixel.

Multi-pixel impulse noise
On X-ray images, especially large-size ones, intensity impulses with definition area S being greater than one pixel may appear. The reason for this is the direct illumination of indirect-conversion X-ray detectors [17] with exceeding threshold pixel capacitance value called "full well capacity of a pixel" or "pixel well depth" under the action of high intensity hard radiation. In the first case, several neighboring photosensitive pixels of matrix detector are directly exposed by high energy X-ray quanta. The second case is the example of spurious illumination called blooming effect [18], due to the limited value of pixel saturation capacity, i.e., the number of electrons that a pixel can hold. Henceforward the charge accumulated in a pixel spreads and redistributes to neighboring ones, which is perceived as several glowing pixels when image is read. Since each pixel has 8 immediate neighbors, maximum defect size is 9 pixels. Such defects of different intensity and sizes randomly distributed over an image are considered as multi-pixel impulse noise. We should note that a real image was recorded with a fairly high level of Gaussian noise: standard deviation of scan-line i c = 383 of this monochrome image the intensities of which span the full scale from 0 (black color) to 1 (white color) is where < G 383 > is the average value of control scan-line (i c = 383) intensity. The ratio of total impulse magnitude to standard deviation is approximately 4:1. Fig. 2. X-ray chip image corrupted by salt impulse noise Fig. 2c shows a magnified image fragment (subimage) containing a marked area, fig. 2d shows an enlarged structure of marked impulse the intensity levels of which span a full 8-bit range from 0 to 255.
In addition to aesthetic discomfort, such impulses can cause more serious troubles, such as data artifacts during the restoration of three-dimensional tomographic images in the space of flat X-ray projections [19].

Idea of new switching filtering
Noise elimination method proposed in the paper is a development of algorithm [8] described above, the essence of which is the analysis of parameter γ (see (2)) and corresponding setting of median filter.
The method is suitable for both excluding "salt" and "pepper", although its idea can be explained using the example of suppressing "salt".
Following the logics of the research, we will take image background equal to average intensity value. In this case, threshold values in the first approximation can be obtained from the analysis of all possible combinations of corrupted and background pixels in idealized images. Further, the values of thresholds when processing real Xray images are refined. This approach to presentation allows us to reveal the essence of the method making possible to build an algorithm without rigorous mathematical theory. The practical suitability of the developed method is demonstrated by processing a large number of real X-ray images.
Some possible combinations of intensity singularities (anomalies) consisting of a center pixel and a few neighbor bright pixels are given in fig. 3

Fig. 3. Combinations of bright pixels in multi-pixel impulses
The maximum number of bright pixels in the singularity is 9. The singularities are presented in increasing number of bright pixels near the center one. To simplify the perception of graphic material, pixel intensities are given on a scale from 0 (black) to 1 (white). Total bright pixels number S and the value of intensity increment γ (2) are written under each combination of pixels. Fig. 4 graphically depicts the relationship between number S of bright pixels in an impulse and the increment of intensity γ (2). This relationship is indicated by small black circles.

The problem to be solved
Let us set the problem of elimination impulses containing different numbers of bright pixels and solve the problem of excluding impulses with maximum size of S = 3 × 3 = 9 pixels (see fig. 3). The impulses of a bigger area are considered as useful small details in an image, which should not be corrupted or corrupted in a minimal way during processing. At the filtration stage, a median filter of the smallest possible size 3 × 3 is used being the guarantee of minimal image blurring.
Since the prerogative of the considered filter is exclusively impulse noise, it should not intrude into the adjacent area of Gaussian noise, for which specialized and effective filters have been developed [20]. Therefore, to fulfill the condition of maximum preservation of Gaussian noise level (and fine structure of a shadow image) during image processing by the proposed filter is considered as another part of the problem. The last statement (concerning Gaussian noise level and image fine structure) is a known fact of deterioration in spatial resolution of a signal when its Gaussian noise is suppressed by hardware or mathematically.

Describing new switching filtering
The algorithm proposed to eliminate multi-pixel impulses follows from the analysis of diagrams in fig. 3

and 4:
 if an impulse is represented by one bright pixel S = 1 (see fig. 3), then to eliminate it by a median filter of size 3 × 3, we need to verify that the condition γ = 4.0, or at least, γ > γ 1 = 3.9 (see fig. 4); if the condition is not met the pixel is not processed with a median filter;  if an impulse is represented by two adjacent pixels S = 2 (in any possible combination, e.g., in fig. 3), one being considered as a center pixel, then to eliminate them by median filter we need a threshold γ = 3.5 as well as the condition of mathematical inequality, e.g., γ > γ 2 = 3.4 that excludes both two-pixel impulses and single-pixel ones (see fig. 4);  if an impulse is represented by three neighboring pixels S = 3 (in any possible combination, e.g., in fig. 3), one being considered as a center pixel, then to eliminate them by median filter we need a threshold γ = 3.0 as well as the condition in the form of inequality, e.g., γ > γ 3 = 2.9 that excludes both three-pixel and two-pixel impulses together with singlepixel ones (see fig. 4);  if an impulse is represented by four neighboring pixels S = 4 (in any possible combination, e.g., in fig. 3), one being considered as a center pixel, then to eliminate them by median filter we need a threshold γ = 2.5 as well as the condition in the form of inequality, e.g., γ > γ 4 = 2.4 that excludes the impulses consisting of four, three, two pixels as well as single-pixel ones (see fig. 4);  for S = 5 threshold γ is more than γ 5 = 1.9;  for S = 6 threshold γ is more than γ 6 = 1.4;  etc. (see. fig. 4).
Trial testing of the algorithm proposed for image processing by a 3 × 3 median filter is carried out on an image template ( fig. 1a) representing three rows of impulses with different sizes.
The result of template processing with threshold value of γ > γ 1 = 3.9 with a single-pixel impulse being eliminated is shown in fig. 5a; threshold value of γ > γ 2 = 3.4 with impulses of 1 and 2 pixels being eliminated is shown in fig. 5b; with threshold value of γ > γ 3 = 2.9 with impulses of 1, 2 and 3 pixels being eliminated is shown in fig. 5c. Fig. 5

. Median filtering of image pattern corrupted by multi-pixel impulses
At threshold value of γ > γ 4 = 2.4 the result of original image processing (see Fig. 1a) is shown in fig. 5d with impulses consisting of 4 and less pixels being eliminated. In this process, initial 5-pixel impulse of the second row is reduced to one pixel, initial 9-pixel impulse of the second row being the target for complete elimination in the problem under consideration is reduced to a cross-shaped 5-pixel impulse. It is worth mentioning that bright square impulses (spots) located in the third row of the pattern with the size of more than 9 pixels have their corner pixels to be eliminated in the course of processing. Such distortions of large sized impulses are considered to be insignificant.
According to the results received and smoothing algorithm logics the original (see fig. 1a) image processing at further threshold γ decrease (i.e., when γ < γ 4 ) is seen as the reason for the elimination of target impulse sized S = 3 × 3 pixels as well as for significant distortion of broad impulses with S > 9. Practical tests have shown an unacceptably high level of image distortion, this conclusion being proven.
Fortunately, to completely eliminate target impulse with S = 3 × 3 there is no need to further reduce threshold γ, since the first iteration of processing with threshold γ > γ 4 = 2.4 causes this impulse to be reduced to a 5-pixel impulse further being reduced to a single-pixel one as a result of another iteration with the same threshold γ > γ 4 = 2.4 (see fig 5e).
Last single-pixel impulse ( fig. 5e) is certain to be eliminated by means of another iteration with threshold γ > γ 1 = 3.9. The result of last smoothing iteration is presented in fig. 5f.
It is worth noting that the result of last two iterations is the absence of additional distortions shown by large impulses (S > 9) located in the third line of the template.
Thus, the analysis of smoothing data shows that to eliminate impulses of size S  9, an original image in fig. 1a should first be processed by median filter with threshold of γ > γ 4 = 2.4. Then, to eliminate residues from initial 5-pixel and 9-pixel impulses (see fig. 5d) one more iteration of the obtained image processing with the same threshold γ > γ 4 = 2.4 is necessary, the third final iteration with threshold γ > γ 1 = 3.9 leading to a single-pixel impulse elimination (see fig. 5e). As a result of three iterations of original image processing with thresholds γ > γ 4 = 2.4, γ > γ 4 = 2.4 and γ > γ 1 = 3.9, the problem of eliminating 9-pixel impulses is solved, while the distortions of intensity singularities of sized S > 9 pixels are negligible as only the corner pixels of such image details are smoothed (see fig. 5f).
The final results in this part of the study defining thresholds γ k with each m-th iteration thus allowing us to eliminate the impulses with definition area equal to and less than S can be seen in Table 1. Therefore, having detected γ > γ k a standard median 3 × 3 filter is applied for smoothing CP at each iteration (see table 1). Here γ k is calculated by formula (2) at each (i, j) image pixel. We should emphasize that despite the algorithm being of three iterations, only sums (2) are determined at each of them. Consequently, the algorithm is as simple as possible, its cost being approximately equal to the cost of other adaptive algorithms studied in the work.

Simulation results
Next, the algorithm to smooth the real images corrupted by impulse noise is tested.
At image processing, the value of standard deviation σ (11) of the image scan-line selected is controlled.
To have one more image processing control criterion, we take the ratio of impulse intensity total amplitude to the value of this standard deviation. This ratio shows the magnitude of impulse excess over background noise and characterizes the degree of impulse noise suppression. Fig. 6 shows the result of applying the proposed switching filter to smooth X-ray image corrupted by impulse noise (see fig. 2). Fig. 6a is the chip subimage (see Fig. 2c). Fig. 6b is the intensity profile of control scanline i c = 383. The significant decrease in the number of impulses compared to the original image in Fig. 2 is also worth mentioning. However, some bright singularities remain in the image after processing. This happens because real image background may be "brighter" than 0.5, and pixel intensity may be "darker" than 1, i.e. they may differ from those values that are the basis of the algorithm proposed. In this case, the values of thresholds γ where intensity impulses processing "starts" turn out to be overestimated, some impulses being skipped.

New filter
Fortunately, thresholds γ (γ 1 = 3.9, γ 2 = 3.4, γ 3 = 2.9, γ 4 = 2.4, etc.) can be reduced without modifying algorithm logic, hence without changing the results of template processing. The diagram in fig. 4 shows the possibility of such reduction. According to this diagram, threshold γ 1 = 3.9 can be reduced up to the boundary of next threshold γ = 3.5 without changing the number of pixels in the processed impulse, i.e. a new threshold for single-pixel impulses elimination will be described by equality γ' 1 = 3.5. For 2-pixel impulses, threshold can be reduced from γ 2 = 3.4 to γ' 2 = 3.0. New boundaries of all thresholds to process multi-pixel impulses are shown by small circumferences in fig. 4.
We emphasize once again that with such a decrease in thresholds, pattern processing results presented in Fig. 5 are not changed; i.e., the algorithm logic remains the same.

Standard filters
The functionalities of the filter proposed and widely accepted standard median (SM) [1], "classical" adaptive median (CAM) [7], switching median (SwM) [10] and MOD [16] spatial filters are compared in the end of the paper.
A standard 3 × 3 median filter [1] that does not sufficiently limit the amplitude of multi-pixel impulse noise in a chip image (see fig. 8a), is strongly decreased in Gaussian noise (σ = 0.056 for control scan-line) (see fig 8b) and, as a contributing factor, defocuses the image. Due to the fact that such processing greatly reduces the dispersion of Gaussian noise, the ratio of impulse amplitude to the value of this noise is quite high and equals 5:1.
"Classical" adaptive median filter [7] also does not lead to noticeable suppression of multi-pixel impulses compared to the initial one ( fig. 2a), but causes only a slight decrease in 3:1 ratio of total impulse amplitude to standard deviation as well as significant decrease in Gaussian noise level to value σ = 0.085, i.e. approximately 1.5 times (see fig. 9). Table 2 and fig. 11 present quantitative test results. A new filter proposed and the filters mentioned above [1,7,10,16] are compared by two parameters (P ). The first parameter is the relative number of noise impulses (P = D / D 0 ) after processing. This parameter shows the degree of impulse noise reduction: 0 % means complete noise suppression. Here, multi-pixel noise is taken as impulse noise, the model of each impulse being shown in fig. 4. The second parameter is relative standard deviations (P = σ / σ 0 ) of intensity profile in the selected row of processed and original images. The closer this parameter to 100 %, the less Gaussian noise is suppressed, which means that fine details of images are better preserved.  . 2a, c) using the standard median filter [1] Switching median [10] and MOD [16] are really good filters. They have the same characteristics: two times reduction of the surge in intensity profile without no reduction of the Gaussian noise ( fig. 10). Fig. 9. Control scan-line after "classical" adaptive median filtering [7] Fig. 10. Control scan-line after MOD filtering [16]   The statistical sample (Fig. 11) of data includes ten Xray images recorded in a real experiment with different shooting parameters, with various ratios of white, gray and black background areas of shadowgraph at different impulse noise density. However, noise density does not exceed 5 %, which is typical for experimental X-ray images. The number of bright anomalies in the images varies from 400 to 7000. Fig. 11. Proposed method compared with other method using ten different X-ray images

Statistical data analysis
Error bars in fig. 11 represent minimum and maximum values of P parameters for all the methods studied.
The analysis of table 2 and fig. 11 data show that the new method proposed fits the best in the first parameter. Filters [10], [16] and the filter proposed supply practically the same values of the second parameter.
The results of processing many different noisy X-ray images with the proposed and alternative filters confirm the conclusions made about the exceptional capacity of a new technique to suppress multi-pixel and standard impulse noise. Fig. 12 shows the result of processing ( fig. 12b) a circuit board X-ray image corrupted by salt-and-pepper noise with 10 % density ( fig. 12a). Almost complete restoration of a source image with preservation of fine details is observed. Therefore, a source image is not shown in the paper.
Thus, the proposed method provides effective suppression of impulse noise, including multi-pixel noise, in real time without noticeable image distortion, i.e. it is the solution to the problem.
Further development of the method will require optimization of threshold values by rigorous mathematical justification. Another way to improve the method is to automate the process of choosing the number of processing iterations and the corresponding threshold values based on the development of algorithms for detecting and analyzing the structure of multi-pixel impulse noise. The method has shown its practical applicability in the processing of grayscale X-ray images; however, there are no restrictions on the use of the method in other applications.

Conclusion
The proposed filtering technique is based on the analysis of intensity increment in each image pixel relative to immediate eight neighbors (2) and on the application of 3 × 3 median filter. Intensity thresholds γ were determined as a function of number S of bright pixels in multipixel impulses, when exceeded, the processing of current pixel by median filter is activated (table 1). Fig. 12. Result of processing a circuit board X-ray image corrupted by salt-and-pepper noise with 10 % density The efficiency of the proposed filter to suppress multipixel impulse noise in X-ray images is shown. The filter is time-efficient and practically does not reduce the level of Gaussian noise, which means it does not defocus images.
The studies have shown that the methods [10], [16] and the proposed one provide approximately the same level of preservation of fine details of images, in contrast to methods [1] and [7], which lead to strong distortions. For most of the classes of the considered images, differing in the average level of intensity, noise density, etc., the new method surpasses the other methods included in this test in terms of the degree of impulse noise suppression. However, for images with a bright background exceeding 90 % of the maximum intensity level, the method [16] begins to win in terms of the degree of suppression of "salt". The same tendency can be seen for a dark background when the "pepper" is suppressed. However, extremely bright or extremely dark images are rarely used in practice, and therefore such the win is not worthy of attention.