You are on page 1of 16

Fi

lt
eri
ngi
nthespat
ialdomai
n(Spat
ialFi
lt
eri
ng)
r
efer
stoi
mageoper
ator
sthatchanget
hegr
ayv
alueatanypi
xel
(
x,y
)dependi
ngont
hepi
xel
val
uesi
nasquar
enei
ghbor
hood
cent
eredat(
x,y
)usi
ngaf
ixedi
ntegermat
ri
xoft
hesamesi
ze.The
i
ntegermat
ri
xi edaf
scal
l il
ter,
mask,
ker
nelorawi
ndow.
Themechani
sm ofspat
ial
fil
ter
ing,
shownbel
ow,
consi
sts
si
mpl
yofmov
ingt
hef
il
termaskf
rom pi
xel
topi
xel
inani
mage.
Ateachpi
xel
(x,
y),
ther
esponseoft
hef
il
teratt
hatpi
xel
is
cal
cul
atedusi
ngapr
edef
inedr
elat
ionshi
p(l
i
nearornonl
i
near
).

Fi
gur
e6.
1Spat
ial
fil
ter
ing

Not
e:

Thesi
zeofmaskmustbeodd(
i.
e.3×3,
5×5,
etc.
)toensur
e
i
thasacent
er.Thesmal
l
estmeani
ngf
ulsi
zei
s3×3.
Li
nearSpat
ialFi
lt
eri
ng(
Conv
olut
ion)
Thepr
ocessconsi
stsofmov
ingt
hef
il
termaskf
rom pi
xel
topi
xel
i
nani
mage.Ateachpi
xel
(x,
y),
ther
esponsei
sgi
venbyasum of
pr
oduct
soft
hef
il
tercoef
fi
ci
ent
sandt
hecor
respondi
ngi
mage
pi
xel
sint
hear
easpannedbyt
hef
il
termask.
Fort
he3×3maskshowni
nthepr
evi
ousf
igur
e,t
her
esul
t(or
r
esponse)
,R,
ofl
i
nearf
il
ter
ingi
s:

=( −1)(−1,
−1, −1)+( 0)(−1,
−1, )+⋯
+(
0,0)(,
)+⋯+(
1,0)(+1,
)+(
1,1)(+1,
+1)

I
ngener
al,
li
nearf
il
ter
i magefofsi
ngofani zeM×Nwi
thaf
il
ter
zem×ni
maskofsi sgi
venbyt
heexpr
essi
on:

(,
)=(,
)(+,
+)

wher m -1)
ea=( / n-l
2andb=( )/2.Togener
ateacompl
ete
f
il
ter
edi
maget
hisequat
ionmustbeappl
i
edf
orx=0,
1,2,
.
..
,M-
1
andy=0,
1,2,
.
..
,N-
1.

Nonl
inearSpat
ialFi
lt
eri
ng
Theoper
ati
onal
soconsi
stsofmov
ingt
hef
il
termaskf
rom pi
xel
t
opi
xel
inani
mage.Thef
il
ter
ingoper
ati
oni
sbasedcondi
ti
onal
l
y
ont
hev
aluesoft
hepi
xel
sint
henei
ghbor
hood,
andt
heydonot
expl
i
cit
lyusecoef
fi
cient
sint
hesum-
of-
product
smanner
.
Forexampl
e,noi
ser
educt
ioncanbeachi
evedef
fect
ivel
y
wi
thanonl
i
nearf
il
terwhosebasi
cfunct
ioni
stocomput
ethe
medi
angr
ay-
lev
elv
aluei
nthenei
ghbor
hoodi
nwhi
cht
hef
il
teri
s
l
ocat
ed.Comput
ati
onoft
hemedi
ani
sanonl
i
nearoper
ati
on.
Exampl
e:
Uset
hef
oll
owi
ng3×3maskt
oper
for
mtheconv
olut
ionpr
ocess
ont
heshadedpi
xel
sint
he5×5i
magebel
ow.Wr
it
ethef
il
ter
ed
i
mage.

0 1/ 0
6
1/ 1/ 1/
6
6 3 30 40 50 70 90
0 1/ 0 40 50 80 60 100
6 35 255 70 0 120
3×3mask 30 45 80 100 130
40 50 90 125 140
5×5i
mage

Sol
uti
on:
1 1 1 1 1

0×30+ ×40+0×50+ ×40+ ×50+ ×80+0×35+ ×255


6 6 3 6 6
+0×70=85
1 1 1 1 1
0×40+ ×50+0×70+ ×50+ ×80+ ×60+0×255+ ×70
6 6 3 6 6
+0×0=65
1 1 1 1 1
0×50+ ×70+0×90+ ×80+ ×60+ ×100+0×70+ ×0
6 6 3 6 6
+0×120=
1 1 1 1 1
0×40+ ×50+0×80+ ×35+ ×255+ ×70+0×30+ ×45
6 6 3 6 6
+0×80=118
andsoon…

30 40 50 70 90
40 85 65 61 100
Fi
l
ter
edi
mage= 35 118 92 58 120
30 84 77 89 130
40 50 90 125 140
Spat
ialFi
lt
ers
Spat
ial
fil
ter
scanbecl
assi
fi
edbyef
fecti
nto:
1.Smoothi
ngSpat
ialFi
lt
ers:al
socal
l
edl
owpassf
il
ter
s.They
i
ncl
ude:
1.
1 Av
eragi
ngl
i
nearf
il
ter
s
1.
2 Or
der
-st
ati
sti
csnonl
i
nearf
il
ter
s.
2.Shar
peni
ngSpat
ialFi
lt
ers:al
socal
l
edhi
ghpassf
il
ter
s.For
exampl
e,t
heLapl
aci
anl
i
nearf
il
ter
.

Smoot
hingSpat
ialFi
lt
ers
ar
eusedf
orbl
urr
ingandf
ornoi
ser
educt
ion.Bl
urr
ingi
s
usedi
npr
epr
ocessi
ngst
epst
o:
r
emov
esmal
ldet
ail
sfr
om ani
magepr
iort
o(l
arge)
obj
ectext
ract
ion
 br
idgesmal
lgapsi
nli
nesorcur
ves.
Noi
ser
educt
ioncanbeaccompl
i
shedbybl
urr
ingwi
thal
i
near
f
il
terandal
sobynonl
i
nearf
il
ter
ing.

Av
eragi
ngl
inearf
il
ter
s
Ther
esponseofav
eragi
ngf
il
teri
ssi
mpl
ytheav
erageoft
he
pi
xel
scont
ainedi
nthenei
ghbor
hoodoft
hef
il
termask.
Theout
putofav
eragi
ngf
il
ter
sisasmoot
hedi
magewi
thr
educed
"
shar
p"t
ransi
ti
onsi
ngr
ayl
evel
s.
Noi
seandedgesconsi
stofshar
ptr
ansi
ti
onsi
ngr
ayl
evel
s.
Thussmoot
hingf
il
ter
sar
eusedf
ornoi
ser
educt
ion;
howev
er,
t
heyhav
etheundesi
rabl
esi
deef
fectt
hatt
heybl
uredges.
Thef
igur
ebel
owshowst
wo3×3av
eragi
ngf
il
ter
s.

1 1 1 1 2 1
1 1 1 1 1 2 4 2
× ×
9 16
1 1 1 1 2 1
St
andar
dav
eragef
il
ter Wei
ght
edav
eragef
il
ter
Not
e:
Wei
ght
edav
eragef
il
terhasdi
ff
erentcoef
fi
cient
stogi
vemor
e
i
mpor
tance(
wei
ght
)tosomepi
xel
satt
heexpenseofot
her
s.
Thei
deabehi
ndt
hati
stor
educebl
urr
ingi
nthesmoot
hing
pr
ocess.

Av
eragi
ngl
i
nearf
il
ter
i magefofsi
ngofani zeM×Nwi
thaf
il
ter
zem×ni
maskofsi sgi
venbyt
heexpr
essi
on:

Togener
ateacompl
etef
il
ter
edi
maget
hisequat
ionmustbe
appl
i
edf
orx=0,
1,2,
.
..
,M-
1andy=0,
1,2,
.
..
,N-
1.

Fi
gurebel
owshowsanex
ampl
eofappl
yi
ngt
hest
andar
dav
eragi
ng
fi
l
ter
.
(
a) (
b)

(
c) (
d)

(
e) (f
)
Fi
gur
e6.
2Ef
fectofaver
agi
ngf
il
ter
.(a)Or
igi
nal
image.(
b)-
(f
)Resul
tsofsmoot
hing
wi
thsquar
eav
eragi
ngf
il
termasksofsi
zesn=3,
5,
9,
15,
and35,
respect
ivel
y.
Asshowni
nthef
igur
e,t
heef
fect
sofav
eragi
ngl
i
nearf
il
terar
e:
1.Bl
urr
ingwhi
chi
sincr
easedwhenev
ert
hemasksi
zei
ncr
eases.
2.Bl
endi
ng(
remov
ing)smal
lobj
ect
swi
tht
hebackgr
ound.
Thesi
zeoft
hemaskest
abl
i
shest
her
elat
ivesi
zeoft
he
bl
endedobj
ect
s.
3.Bl
ackbor
derbecauseofpaddi
ngt
hebor
der
soft
heor
igi
nal
i
mage.
4.Reducedi
magequal
i
ty.

Or
der
-st
ati
sti
csf
il
ter
s
ar
enonl
i
nearspat
ial
fil
ter
swhoser
esponsei
sbasedonor
der
ing
(
ranki
ng)t
hepi
xel
scont
ainedi
nthenei
ghbor
hood,
andt
hen
r
epl
aci
ngt
hev
alueoft
hecent
erpi
xel
wit
hthev
aluedet
ermi
nedby
t
her
anki
ngr
esul
t.
Exampl
esi
ncl
udeMax,
Min,
andMedi
anf
il
ter
s.

Medi
anf
il
ter
I
trepl
acest
hev
alueatt
hecent
erbyt
hemedi
anpi
xel
val
uei
n
t
henei
ghbor
hood,
(i.
e.t
hemi
ddl
eel
ementaf
tert
heyar
esor
ted)
.
Medi
anf
il
ter
sar
epar
ti
cul
arl
yusef
uli
nremov
ingi
mpul
senoi
se
(
alsoknownassal
t-
and-
peppernoi
se)
.Sal
t=255,
pepper=0
gr
ayl
evel
s.
I
na3×3nei
ghbor
hoodt
hemedi
ani
sthe5t
hlar
gestv
alue,
in
a5×5nei
ghbor
hoodt
he13t
hlar
gestv
alue,
andsoon.
Forexampl
e,supposet
hata3×3nei
ghbor
hoodhasgr
ay
l
evel
s(10,
20,
0,20,
255,
20,
20,
25,
15)
.Thesev
aluesar
esor
ted
as(
0,10,
15,
20,
20,
20,
20,
25,
255)
,whi
chr
esul
tsi
namedi
anof20
t
hatr
epl
acest
heor
igi
nal
pixel
val
ue255(
sal
tnoi
se)
.
Exampl
e:
Consi
dert
hef
oll
owi
ng5×5i
mage:
20 30 50 80 100
30 20 80 100 110
25 255 70 0 120
30 30 80 100 130
40 50 90 125 140
Appl
ya3×3medi
anf
il
teront
heshadedpi
xel
s,andwr
it
ethe
f
il
ter
edi
mage.

Sol
uti
on
20 30 50 80 100 20 30 50 80 100
30 20 80 100 110 30 20 80 100 110
25 255 70 0 120 25 255 70 0 120
30 30 80 100 130 30 30 80 100 130
40 50 90 125 140 40 50 90 125 140
Sor
t: Sort
20,
25,30,
30,
30,
70,
80,
80,
255 0,20,30,
70,
80,
80,
100,
100,
255

20 30 50 80 100
30 20 80 100 110
25 255 70 0 120
30 30 80 100 130
40 50 90 125 140
Sort
0,70,80,
80,
100,
100,
110,
120,
130

20 30 50 80 100
30 20 80 100 110
25 30 80 100 120
Fi
l
ter
edI
mage=
30 30 80 100 130
40 50 90 125 140
Fi
gur
ebel
owshowsanex
ampl
eofappl
yi
ngt
hemedi
anf
il
ter
onani
magecor
rupt
edwi
thsal
t-
and-
peppernoi
se.

(
a) (
b)

(c)
Fi
gur
e6.
3Ef
fectofmedi
anf
il
ter
.(a)I
magecor
rupt
edbysal
t&peppernoi
se.(
b)
Resul
tofappl
yi
ng3×3st
andar
dav
eragi
ngf
il
teron(
a).(
c)Resul
tofappl
yi
ng3×3
medi
anf
il
teron(
a).

Asshowni
nthef
igur
e,t
heef
fect
sofmedi
anf
il
terar
e:
1.Noi
ser
educt
ion
2.Lessbl
urr
ingt
hanav
eragi
ngl
i
nearf
il
ter
Shar
peni
ngSpat
ialFi
lt
ers
Shar
peni
ngai
mst
ohi
ghl
i
ghtf
inedet
ail
s(e.
g.edges)i
nani
mage,
orenhancedet
ail
thathasbeenbl
urr
edt
hrougher
ror
sori
mper
fect
capt
uri
ngdev
ices.
I
magebl
urr
ingcanbeachi
evedusi
ngav
eragi
ngf
il
ter
s,andhence
shar
peni
ngcanbeachi
evedbyoper
ator
sthati
nver
tav
eragi
ng
oper
ator
s.I
nmat
hemat
ics,
aver
agi
ngi
sequi
val
entt
otheconcept
ofi
ntegr
ati
on,
anddi
ff
erent
iat
ioni
nver
tsi
ntegr
ati
on.Thus,
shar
peni
ngspat
ial
fil
ter
scanber
epr
esent
edbypar
ti
alder
ivat
ives.

Par
ti
alder
ivat
ivesofdi
git
alf
unct
ions
Thef
ir
stor
derpar
ti
alder
ivat
ivesoft
hedi
git
almagef
i (x,
y)ar
e:
=(,
+1)−(,
)
= (+1,)− (,)
and

Thefi
rstder
ivat
ivemust
be:

1)zer
oal
ongf
latsegment
s(i
.e.const
antgr
ayv
alues)
.
2)non-
zer
oatt
heout
setofgr
ayl
evel
steporr
amp
(
edgesornoi
se)
3)non-
zer
oal
ongsegment
sofcont
inui
ngchanges(
i.
e.
ramps)
.

Thesecondor
derpar
ti
alder
ivat
ivesoft
hedi
git
almagef
i (x,
y)ar
e:

=(+1,
)+(−1,
)−2(,
)

+1)+(,
=(, −1)−2(,
)
Thesecondder
ivat
ivemustbe:
1)zer
oal
ongf
latsegment
s.
2)nonzer
oatt
heout
setandendofagr
ay-
lev
elst
eporr
amp;
3)zer
oal
ongr
amps

Consi
dert
heexampl
e

bel
ow:

Fi
gur
e6.
4Exampl
eofpar
ti
alder
ivat
ives

Weconcl
udet
hat
:
1stder
ivat
ivedet
ect
sthi e2ndder
ckedgeswhi
l ivat
ive
det
ect
sthi
nedges.
2ndder
ivat
ivehasmuchst
rongerr
esponseatgr
ay-
lev
elst
ep
han1stder
t ivat
ive.
Thus,
wecanexpectasecond-
orderder
ivat
ivet
oenhancef
ine
det
ail
(thi
nli
nes,
edges,
incl
udi
ngnoi
se)muchmor
ethanaf
ir
st-
or
derder
ivat
ive.
TheLapl
aci
anFi
lt
er
TheLapl
aci
anoper
at magef
orofani (x,
y)i
s:
+
∇=

Thi
sequat
ioncanbei
mpl
ement
edusi
ngt
he3×3mask:
−1 −1 −1
−1 8 −1
−1 −1 −1
Si
ncet
heLapl
aci
anf
il
teri
salinearspat
ial
fil
ter
,wecanappl
yit
usi
ngt
hesamemechani
sm oft
heconv
olut
ionpr
ocess.Thi
swi
l
l
pr
oduceal
apl
aci
ani
maget
hathasgr
ayi
shedgel
i
nesandot
her
di
scont
inui
ti
es,
all
super
imposedonadar
k,f
eat
urel
ess
backgr
ound.
Backgr
ound f
eat
ures can be "
recov
ered" whi
l
e st
il
l
pr
eser
vingt
heshar
peni
ngef
fectoft
heLapl
aci
anoper
ati
on
si
mpl
ybyaddi
ngt
heor
igi
nal
andLapl
aci
ani
mages.
(,)=(,)+∇(,
)
Thef
igur
ebel
owshowsanexampl
eofusi
ngLapl
aci
anf
il
tert
o
shar
penani
mage.
(
a) (
b)

(
c)

Fi
gur
e6.
5Exampl
eofappl
yi
ngLapl
aci
anf
il
ter
.(a)Or
igi
nal
image.(
b)Lapl
aci
ani
mage.
(
c)Shar
penedi
mage.

You might also like