You are on page 1of 10

ECE-533

Adaptive Median Filtering of Still Images

by

Arjun Arunachalam and Shyam Bharat


Contents:

1. Theory 2

2. Implementation and Testing 3

3. Matlab Implementation 4

4. Results 6

5. Conclusions 9

6. References 9

2
Theory:

The Adaptive Median Filter is designed to eliminate the problems faced with the standard
median filter. The basic difference between the two filters is that, in the Adaptive Median
Filter, the size of the window surrounding each pixel is variable. This variation depends
on the median of the pixels in the present window. If the median value is an impulse, then
the size of the window is expanded. Otherwise, further processing is done on the part of
the image within the current window specifications. ‘Processing’ the image basically
entails the following: The center pixel of the window is evaluated to verify whether it is
an impulse or not. If it is an impulse, then the new value of that pixel in the filtered image
will be the median value of the pixels in that window. If, however, the center pixel is not
an impulse, then the value of the center pixel is retained in the filtered image. Thus,
unless the pixel being considered is an impulse, the gray-scale value of the pixel in the
filtered image is the same as that of the input image. Thus, the Adaptive Median Filter
solves the dual purpose of removing the impulse noise from the image and reducing
distortion in the image. Adaptive Median Filtering can handle the filtering operation of an
image corrupted with impulse noise of probability greater than 0.2. This filter also
smoothens out other types of noise, thus, giving a much better output image than the
standard median filter.
We have implemented the above-mentioned adaptive median filter in Matlab. Our inputs
include deciding the initial size of the window, the maximum allowable size of the
window for a particular pixel etc. For example, for pixels located near the edge of the
image, we would be devising a method for determining the maximum window size, the
pixels that would make up the window beyond the image dimensions etc.

3
Implementation and Testing:

Our filter is based on the algorithm described in the book. A brief summary thus follows:

The adaptive filter works on a rectangular region Sxy. The adaptive median filter changes
the size of Sxy during the filtering operation depending on certain criteria as listed below.
The output of the filter is a single value which the replaces the current pixel value at (x,
y), the point on which Sxy is centered at the time. The following notation is adapted from
the book and is reintroduced here:

Zmin = Minimum gray level value in Sxy.

Zmax = Maximum gray level value in Sxy

Zmed = Median of gray levels in Sxy

Zxy = gray level at coordinates (x, y)

Smax = Maximum allowed size of Sxy

The adaptive median filter works in two levels denoted Level A and Level B as
follows:

Level A: A1= Zmed - Zmin


A2= Zmed - Zmax

If A1 > 0 AND A2 < 0, Go to level B


Else increase the window size

If window size <= Smax repeat level A


Else output Zxy.

Level B: B1 = Zxy – Zmin


B2 = Zxy – Zmin
If B1 > 0 And B2 < 0 output Zxy
Else output Zmed.

The algorithm has three main purposes:


(a) To remove ‘Salt and Pepper’ noise.
(b) To smoothen any non impulsive noise.

4
(c) To reduce excessive distortions such as too much thinning or thickening of object
boundaries.

Matlab implementation of the above algorithm:

%% Adaptive Median Filtering - The Code


ip1 = imread ('shyam-gs.bmp'); %% Undistorted image
ip = imnoise (ip1,'salt & pepper',0.25); %% Image corrupted with 'Salt and
Pepper Noise'

ip_median_filt1 = medfilt2(ip); %% Applying the median filter to the noisy image


with window dimensions of 3x3 pixels
ip_median_filt2 = medfilt2(ip,[4,4]); %% Applying the median filter to the noisy
image with window dimensions of 4x4 pixels
figure(1), clf;
subplot (2, 1, 1), imshow (ip, []);
subplot (2, 1, 2), imshow (ip_median_filt1, []);

%% We now proceed with the adaptive median filtering of the noisy image and
%% prove that the results are better than those of the standard median filter
shown
%% above

%% Packing zeros around the edge pixels of the noisy input image so as to
%% allow the facilitate the processing of edge-pixels of the image

ip_edge = zeros (212,276);

ip_convert = double (ip);

ip_edge (11:202, 11:266) = ip_edge (11:202, 11:266) + ip_convert;

smax=9;

for i=11:202
for j=11:266
sx=3;
sy=3;
while ((sx<=smax) & (sy<=smax))
ip_edge_min = ip_edge (i, j);
ip_edge_max = ip_edge (i, j);

5
ip_edge_median = median(median(ip_edge((i-floor(sx/2)):(i+floor(sx/2)),(j-
floor(sy/2)):(j+floor(sy/2)))));
for k= (i-floor (sx/2)) :( i+floor (sx/2))
for l= (j-floor (sy/2)) :( j+floor (sy/2))
if ip_edge (k, l) < ip_edge_min
ip_edge_min = ip_edge (k, l);
end
if ip_edge (k, l) > ip_edge_max
ip_edge_max = ip_edge (k, l);
end
End
end
A = ip_edge_median - ip_edge_min;
B = ip_edge_median - ip_edge_max;
if (A>0) & (B<0)
C = ip_edge (i, j) - ip_edge_min;
D = ip_edge (I) - ip_edge_max;
if (C>0) & (D<0)
pledge (i, j) = ip_edge (i, j);
break
else
ip_edge (i, j) = ip_edge_median;
break
end
else
sx=sx+2;
sy=sy+2;
if (sx>smax) & (sy>smax)
ip_edge(i,j) = ip_edge(i,j);
end
end
end
end
end
figure(2), clf;
imshow(ip_edge,[]);

6
Considering the three criteria mentioned earlier, the following tests were conducted:

The adaptive median filter is designed to remove impulsive noise from images.
Therefore, our algorithm’s performance was first tested with basic salt and pepper noise
with a noise density of 0.25. The next test involves processing images that contain
impulsive and/or non-impulsive noise. It is well known that the median filter does not
provide sufficient smoothening of non-impulsive noise. Therefore, Gaussian and ‘salt
and pepper’ noise were added to the image which was then processed by the algorithm.

Results:

(a) (b)
Fig1:
(a) The image with ‘salt and pepper’ noise.
(b) Output of the standard median filter.

7
Fig 2: Output of the adaptive median filter shows the improvement in performance with respect to the standard
median filter. The image has been zero padded along the edges to show the improvements along the edges.

Fig 3: (a) (b)

(a) The image with white Gaussian noise. (b) The output image of a standard median filter.

Fig 4: The output of the adaptive median image.

The adaptive median filter does a fairly good job of smoothening the image out in the
presence of non-impulsive noise.

8
Outputs from the test with both types of noise:

Fig 5: (a)

(a) The starting image with both types of noise.


(b) Output of the standard median filter.

Fig 6: Output of the adaptive median filter.

9
The performance of the adaptive median filter is poor in the presence of both types of
noise.

Conclusions:

The adaptive median filter successfully removes impulsive noise from images. It does a
reasonably good job of smoothening images that contain non-impulsive noise. When
both types of noise are present, the algorithm is not as successful in removing impulsive
noise and its performance deteriorates. Overall, the performance is as expected and the
successful implementation of the adaptive median filter is presented.

References:

Adaptive median filters: new algorithms and results


Hwang, H.; Haddad, R.A.;
Image Processing, IEEE Transactions on, Volume: 4 Issue: 4, April 1995: Page(s): 499
-502

Selective removal of impulse noise based on homogeneity level information


Gouchol Pok; Jyh-Charn Liu; Nair, A.S.;
Image Processing, IEEE Transactions on , Volume: 12 Issue: 1, Jan. 2003: Page(s): 85
-92

10

You might also like