<s>
The	O
median	B-Algorithm
filter	I-Algorithm
is	O
a	O
non-linear	O
digital	O
filtering	O
technique	O
,	O
often	O
used	O
to	O
remove	O
noise	O
from	O
an	O
image	O
or	O
signal	O
.	O
</s>
<s>
Such	O
noise	O
reduction	O
is	O
a	O
typical	O
pre-processing	O
step	O
to	O
improve	O
the	O
results	O
of	O
later	O
processing	O
(	O
for	O
example	O
,	O
edge	B-Algorithm
detection	I-Algorithm
on	O
an	O
image	O
)	O
.	O
</s>
<s>
Median	B-Algorithm
filtering	I-Algorithm
is	O
very	O
widely	O
used	O
in	O
digital	B-Algorithm
image	I-Algorithm
processing	I-Algorithm
because	O
,	O
under	O
certain	O
conditions	O
,	O
it	O
preserves	O
edges	O
while	O
removing	O
noise	O
(	O
but	O
see	O
the	O
discussion	O
below	O
)	O
,	O
also	O
having	O
applications	O
in	O
signal	O
processing	O
.	O
</s>
<s>
The	O
main	O
idea	O
of	O
the	O
median	B-Algorithm
filter	I-Algorithm
is	O
to	O
run	O
through	O
the	O
signal	O
entry	O
by	O
entry	O
,	O
replacing	O
each	O
entry	O
with	O
the	O
median	O
of	O
neighboring	O
entries	O
.	O
</s>
<s>
the	O
median	B-Algorithm
filter	I-Algorithm
is	O
not	O
a	O
separable	B-Algorithm
filter	I-Algorithm
)	O
.	O
</s>
<s>
To	O
demonstrate	O
,	O
using	O
a	O
window	O
size	O
of	O
three	O
with	O
one	O
entry	O
immediately	O
preceding	O
and	O
following	O
each	O
entry	O
,	O
a	O
median	B-Algorithm
filter	I-Algorithm
will	O
be	O
applied	O
to	O
the	O
following	O
simple	O
one-dimensional	O
signal	O
:	O
</s>
<s>
Code	O
for	O
a	O
simple	O
two-dimensional	O
median	B-Algorithm
filter	I-Algorithm
algorithm	O
might	O
look	O
like	O
this	O
:	O
</s>
<s>
The	O
naïve	O
implementation	O
described	O
above	O
sorts	O
every	O
entry	O
in	O
the	O
window	O
to	O
find	O
the	O
median	O
;	O
however	O
,	O
since	O
only	O
the	O
middle	O
value	O
in	O
a	O
list	O
of	O
numbers	O
is	O
required	O
,	O
selection	B-Algorithm
algorithms	I-Algorithm
can	O
be	O
much	O
more	O
efficient	O
.	O
</s>
<s>
Furthermore	O
,	O
some	O
types	O
of	O
signals	O
(	O
very	O
often	O
the	O
case	O
for	O
images	O
)	O
use	O
whole	O
number	O
representations	O
:	O
in	O
these	O
cases	O
,	O
histogram	B-Algorithm
medians	O
can	O
be	O
far	O
more	O
efficient	O
because	O
it	O
is	O
simple	O
to	O
update	O
the	O
histogram	B-Algorithm
from	O
window	O
to	O
window	O
,	O
and	O
finding	O
the	O
median	O
of	O
a	O
histogram	B-Algorithm
is	O
not	O
particularly	O
onerous	O
.	O
</s>
<s>
Median	B-Algorithm
filtering	I-Algorithm
is	O
one	O
kind	O
of	O
smoothing	B-Application
technique	O
,	O
as	O
is	O
linear	B-Error_Name
Gaussian	I-Error_Name
filtering	I-Error_Name
.	O
</s>
<s>
All	O
smoothing	B-Application
techniques	O
are	O
effective	O
at	O
removing	O
noise	O
in	O
smooth	O
patches	O
or	O
smooth	O
regions	O
of	O
a	O
signal	O
,	O
but	O
adversely	O
affect	O
edges	O
.	O
</s>
<s>
For	O
small	O
to	O
moderate	O
levels	O
of	O
Gaussian	O
noise	O
,	O
the	O
median	B-Algorithm
filter	I-Algorithm
is	O
demonstrably	O
better	O
than	O
Gaussian	B-Error_Name
blur	I-Error_Name
at	O
removing	O
noise	O
whilst	O
preserving	O
edges	O
for	O
a	O
given	O
,	O
fixed	O
window	O
size	O
.	O
</s>
<s>
However	O
,	O
its	O
performance	O
is	O
not	O
that	O
much	O
better	O
than	O
Gaussian	B-Error_Name
blur	I-Error_Name
for	O
high	O
levels	O
of	O
noise	O
,	O
whereas	O
,	O
for	O
speckle	B-Algorithm
noise	I-Algorithm
and	O
salt-and-pepper	B-Algorithm
noise	I-Algorithm
(	O
impulsive	O
noise	O
)	O
,	O
it	O
is	O
particularly	O
effective	O
.	O
</s>
<s>
Because	O
of	O
this	O
,	O
median	B-Algorithm
filtering	I-Algorithm
is	O
very	O
widely	O
used	O
in	O
digital	B-Algorithm
image	I-Algorithm
processing	I-Algorithm
.	O
</s>
