![](https://csdnimg.cn/release/download_crawler_static/10134698/bg1.jpg)
IEEE
TRANSACTIONS
ON
ACOUSTICS,
SPEECH,
AND
SIGNAL
PROCESSING,
VOL.
ASP-27, NO.
1,
FEBRUARY
1979
13
A Fast Two-Dimensional Median Filtering Algorithm
Aktmcz-We present a fast algorithm for two-dimensional median
fiitering. It
is based
on
storing and updating the
gray
level histogram
of
the picture elements in
the
window. The algorithm is much faster
than
conventional
sorting methods.
For
a window size of m
X
n, the
com-
puter time
required
is
O(n).
I.
INTRODUCTION
T
UKEY
[
13,
[2]
was among the first who suggested the use
of median filters for signal smoothing. More recently,
Rabiner, Samgur, and Schmidt
[3]
and Jayant
[4]
applied
median filters to speech processing;Pratt [5] and Frieden
[6]
applied them to image processing.
In terms of image processing, median filtering is defmed as
follows.
Let
[xij] be the matrix representing a digitized image.
Then the result of the median filtering with
an
m
X
n (where
m,
n
=
odd integers) window is an image [yij] where yij is
equal to the median of the gray levels of the picture elements
lying in an m
X
n window centered at the picture element
xij
in
the input image. Throughout this paper, by an
m
X
n win-
dow, we mean a window which has m pels in the horizontal
direction and
n
pels
in
the vertical direction. In computer cal-
culation, the output image is usually computed in the conven-
Although it is well known that median filtering is useful for
reducing random noise (especially when the noise amplitude
probability density has large tails) and periodic patterns, theo-
retical results on its behavior are nonexistent in the open liter-
ature. Recently, Tyan [7] and Justusson
[8]
have obtained
some interesting analytical results. Justusson studied the sta-
tistical behavior of median filters, while Tyan studied the fixed
points of median filtering among other things. We hope their
results will be published soon.
In
this
paper, we are concerned with only the computational
aspects of two-dimensional median filtering. Conventional
sorting methods, such as Quicksort [9], are time-consuming.
To obtain the median of m
X
n numbers, the average number
of comparisons is typically proportional to mn assuming the
original ordering is random. The fast algorithm we report
here requires only approximately (2n
t
10) comparisons.
tionalscanningorder:~,,,~l2,yl3,...,~2~,~22,~23,....
Manuscript received February
14,
1978; revised August
31,
1978.
This
work was supported by
the
Defense Advanced Research Projects
Agency under Contract MDA 903-77-G-1.
The
authors are with the School of Electrical Engineering, Purdue
University, West Lafayette,
IN
47907.
11.
A FAST TWO-DIMENSIONAL
MEDIAN
FILTERING
ALGORITHM
In doing median filtering, we are
computingrunningmedians.
From one output picture element
to
the next, the m
X
n win-
dow moves only one column. To get the numbers in the new
window from those in the preceding window, we throw away
n points and add in
n
new points. The remaining mn-2n num-
bers are unchanged. To take advantage of this, a fast median
filtering algorithm is developed which is based on storing the
gray level histogram of the mn picture elements (pels) in the
window, and updating it as the window moves.
The algorithm consists of the following steps:
Step
I:
Set up the gray level histogram of the first window
and find the median. Also, make the count, ltmdn of the
number of pels with gray level less than the median.
Step
2:
Move to the next window by deleting the leftmost
column
of
the (previous) window and adding one column to
the right. The histogram is updated.
So
is the count ltmdn.
Now ltmdn stores the number of pels in the current window
having gray levels less than the median of the previous window.
Step
3:
Starting from the median of the previous window,
we move
up/down
the histogram bins one at a time if the
count ltmdn is
not greaterlgreater
than [number of pels
in
a
window divided by 21 and update the count ltmdn until the
median bin
is
reached.
Step
4:
Stop if the end of the line is reached. Otherwise go
to Step
2.
Note:
In Step
3,
if the count 1 tmdn is
not greater
than
[num-
ber of pels in a window divided by
21
,
then we may have the
same median as before and, therefore, do not need to move.
The exact procedure is described below in pidgin Algol:
Algorithm Fast Median Filtering
begin
comment This algorithm
is
doing median filtering of an
comment hist[0:255]
:
histogram array;
comment mdn
:
median value in
a
window;
comment
1
tmdn
:
number of pels having gray levels less
than mdn in a window;
comment left. column
[0:
wind0w.y size
-
11
:
the left-
most column of the previous window;
comment right. column
[0:
wind0w.y size
-
11
:
the
rightmost column of the current window;
comment All the above variables and arrays are global;
image
;
0096-3518/79/0200-0013$00.75
0
1979 IEEE