Morphologicaloperators
PartI
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Morphology
Whatismorphology?▶ Commonlydenotesabranchofbiologythatdealswiththeformandstructureof
animalsandplants
Whatismathema:calmorphology?▶ Atoolforextrac:ngimagecomponentsthatareusefulinthe
- representa:onanddescrip:onofregionshapes(boundaries,skeletons,convexhull,…)- pre-orpost-processing(morphologicalfiltering,thinning,andpruning)
▶ Mathema:calmorphologydealswithsettheory
Whenisituseful?▶ pre-processing(noisefiltering,shapesimplifica:on,boundariessmoothing,…)
▶ enhancingobjectstructure(skeletoniza:on,convexhull,…)
▶ segmenta:on(watershed,…)
▶ quan:ta:vedescrip:on(area,perimeter,…)
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Whatisaset?▶ Collec6onofdis:nctobjects(e.g.forimagescollec:onofpixels)
Basicsetopera:ons
Recallmathema6caltools
AB
SubsetA ✓ B
A B
UnionASB
A B
Intersec:onATB
A B
ComplementAc = {w | w /2 A}
AB
DisjointATB = ;
AB
DifferenceB \A = {w | w 2 B,w /2 A}
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Recallmathema6caltools
Originalset
Transla:on
Reflec:on
B̂ = {w | w = �b, for b 2 B}
(B)z = {c | c = b+ z, for b 2 B}
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Whataremorphologicaloperators?
Localpixeltransforma0onforprocessingregionshapes
MostoTenusedonbinaryimages
Logicaltransforma:onbasedoncomparisonofpixelneighbourhoodswithaspecificpaVern(structuringelement)▶ Erosion
▶ Dila:on
▶ Opening
▶ Closing
▶ Hit-or-misstransforma:on
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Binary morphology
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Structuringelement(SE)
Smallsetwithapredefinedshapetoprobetheimageunderstudy▶ simpleshape
▶ binaryimage
▶ welldefinedorigin(usuallythecenterofgravityorsymmetry)
Itisusefultoadapttheshapetoberectangular
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
HowweuseSE?
Wecomparethestructuringelementtotheneighbourhoodofeachpixel▶ Inparallelforeachpixelwe- checkifSEis“sa:sfied”- wemarkthepixelsthatsa:sfytheSEandthenweperformthedesiredmorphologicalopera:on(erosion,dila:on,…)
Example
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
FiDng,hiDngandmissing
GivenastructuringelementSandabinaryimageI
SfitsIatxif
ShitsIatxif
SmissesIatxif
{y | y = x+ s, s 2 S} ⇢ I
{y | y = x� s, s 2 S}T
I 6= ;
{y | y = x� s, s 2 S}T
I = ;
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
ErosionofasetAbyastructuringelementB▶ allthepointzinAsuchthatBisincludedinAwhentheoriginofBcoincideswithz
(i.e.allthepointsinAatwhichBfitsA)
Erosion
A B = {z | (B)z ✓ A} = {z | (B)z\
Ac = ;}
= {z | z + b 2 A for every b 2 B} N.B.Here“white”meansthatthevaluecanbe0or1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Erosionexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Erosionexample2
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Erosionproper6es
itshrinksorthinsobjectsinabinaryimages▶ actslikea“filter”
itisnotcommuta:ve▶
Itisanincreasingtransforma:on▶
A B 6= B A
A ✓ C ) A B ✓ C B
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Dila6on
Dila:onofasetAbyastructuringelementB▶ allthepointzinAsuchthatBflippedandtranslatedbyzhasnon-emptyintersec:on
withA(i.e.allthepointsinAatwhichflippedBhitsA)
�
A�B =nz | (B̂)z
\A 6= ;
o=
nz |
h(B̂)z
\Ai✓ A
o
= {z | z = a+ b, a 2 A and b 2 B}
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Dila6onexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Dila6onexample2
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Dila6onproper6es
itgrowsorthickensobjectsinabinaryimages▶ actslikea“spa:alconvolu:on”usingtheSEasconvolu:onmask
itiscommuta:ve▶
itisassocia:ve▶
Itisanincreasingtransforma:on▶
A�B = B �A
A� (B � C) = (A�B)� C
A ✓ C ) A�B ✓ C �B
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
ErosionvsDila6on
Erosion▶ RemovalofstructuresofcertainshapeandsizegivenbytheSE
Dila:on▶ FillingofholesoraddingbordersofcertainshapeandsizegivenbytheSE
Erosionanddila:onaredualopera:ons▶
▶
IfBissymmetricwithrespecttoitsorigin,wecanobtaintheerosionoftheimageAbyBsimplybydila:ngthebackgroundoftheimagewith
thesameBandcomplemen:ngtheresult.
(A B)c = Ac � B̂
(A�B)c = Ac B̂
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Dualityexample
A
B
B̂
Ac
A B
Ac � B̂
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Combiningerosionanddila6on
Why?▶ Toremovestructuresand/orfillholeswithoutaffec:ngtheremainingparts
How?▶ bycombiningerosionanddila:onusingthesamestructuringelement
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Opening
OpeningofasetAbythestructuringelementB▶ erosionofAbyBfollowedbyadila:onoftheresultbyB
Proper:es▶ smoothesthecontour
▶ breaksnarrowisthmuses
▶ eliminatesprotrusions
�
A�B = (A B)�BA�B
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Closing
ClosingofasetAbythestructuringelementB▶ dila:onofAbyBfollowedbyanerosionoftheresultbyB
Proper:es▶ smoothessec:onsofthecontour
▶ fusesnarrowbreaksandlongthingulfs
▶ eliminatessmallholes
▶ fillsgapsincontour
A•B = (A�B) B
•
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Opening/Closingexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Opening/Closingexample2
Closing
Opening
Structuringelement
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Proper6es
Opening▶ isasubset(subimage)ofA
▶ Itisanincreasingfunc:on
▶ Itisidempotent,i.e.
Closing▶ Aisasubset(subimage)of
▶ Itisanincreasingfunc:on
▶ Itisidempotent,i.e.
Openingandclosingaredualopera:ons▶
A•BC ✓ D ) C•B ✓ D•B
(A•B)•B = A•B
A�B
C ✓ D ) C �B ✓ D �B
(A�B)�B = A�B
(A•B)c = (Ac � B̂)
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Morphologicalfiltering
Toremoveholesintheforegroundandislandsinthebackground▶ dobothopeningandclosing
ThesizeandshapeofthestructuringelementdetermineswhichfeaturewillsurviveaTerthefiltering
Intheabsenceofknowledgeabouttheshapeofthefeaturestoremove,useacircularSE
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Morphologicalfilteringexample
Closeandthenopen
Openandthenclose
Structuringelement
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Hit-or-MissTransforma6on
Searchesforanexactmatchofthestructuringelement
GivenastructuringelementB=(B1UB2),thematchofBinAis
▶ findsamatchin(hit)
▶ findsamatchin(miss)
~
A~B = (A B1)T(Ac B2)
B1
B2
A
Ac
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Hit-or-MissTransforma6onexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Hit-or-MissTransforma6onexample2
B = (S1, S2)
B = (S2, S3)
B = (S4, S5)
Morphologicaloperators
PartII
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Applications
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Whydoweusemorphologicaloperators?
Representa:onanddescrip:onofashape▶ extrac:ngboundaries
▶ extrac:ngconnectedcomponents
▶ extrac:ngtheconvexhull
▶ skeletonizearegion
Pre/Post-processingsteps▶ regionfilling
▶ regionthinning
▶ regionthickening
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Boundaryextrac6on
CombiningerosionbyastructuringelementBanddifferencebetweensets
�(A) = A \ (A B)
\
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Boundaryextrac6onexample
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Holesfilling
Combiningsetdila:on,complementa:onandintersec:on▶ Aholeisdefinedasabackgroundregionsurroundedbyaconnectedborderof
foregroundpixels
Algorithm▶ GivenapointPinsideaholeset
▶ whiledo end
▶
Wecallthiscondi0onaldila0on
X0 = P
Xk 6= Xk�1
Xk = (Xk�1 �B)T
Ac
XF = XkSA
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Holesfillingexample
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Extrac6onofconnectedcomponents
Combiningsetdila:onandintersec:on▶ AconnectedcomponentSisdefinedasallthepixelsinSforwhichthereexistsapath
thatconnectthemconsis:ngen:relyofpixelsinS
Algorithm▶ GivenapointPinsideAset
▶ whiledo end
Itisagainacondi0onaldila0on
Xk 6= Xk�1
Xk = (Xk�1 �B)T
Ac
X0 = P
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Connectedcomponentsexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Combininghit-or-misstransforma:onandunion▶ AsetAissaidtobeconvexifthestraightlinesegmentjoininganytwopointsinAlies
en0relywithinA
▶ TheconvexhullC(A)ofanarbitrarysetAisthesmallestconvexsetcontainingA
Algorithm▶ Define4structuringelements
▶ Ini:alize
▶ whiledo end
▶
▶ TogetthesmallestconvexsetcontainingAwelimitgrowthtotheminandmaxcoordinatesofA
N.B.Here“x” meansthatthevaluecanbe0or1
ConvexHull
Xik = (Xi
k�1 ~Bi)SA
Bi i = 1, 2, 3, 4
Xi0 = A i = 1, 2, 3, 4
Xik 6= Xi
k�1
C(A) =4[
i=1
Xik
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Thinning
Combininghit-or-misstransforma:onandintersec:on▶ removespixelsfromthesetAusingastructuringelementBun:lonlyanarrowset
remains
Algorithm▶ GivenasequenceofnSEs
▶ Letand
▶ whiledo end
⌦
A⌦B = AT(A~B)c
{B} = (B1, . . . , Bn)
Xn = A
Xn 6= Y
Y = X0 = 0N⇥M
Y = Xn
X0 = Xn
Xi = Xi�1
\(Xi�1 ~Bi)c i = 1, . . . , n
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Thinningexample
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Thickening �
Hit-or-misstransforma:onandunion▶ isthemorphologicaldualofthinningandisdefinedby
Algorithm▶ Compute
▶ PerformthinningalgorithmofusingthesequenceofnSEs
▶ TakeonlytheconnectedcomponentcontainingA
A�B = AS(A~B)
Ac
{B} = (B1, . . . , Bn)
A Ac
Thinning Complementofthinning
Thickeningresults
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Skeletoniza6on
Itisexpressedintermsoferosionsandopenings▶ Maximumdisk:largestdiskincludedinA,touchingtheboundaryofAattwoormore
differentplaces
▶ Skeleton:setofcentersofthemaximumdisks
Algorithm▶ UsingestructuringelementB
▶ Thek-thskeletonsubsetis
▶ Theskeletonistheunionofallthesubsets
▶ Wecanobtaintheoriginalimageusingdila:on
S(A) =K[
k=0
Sk(A)
Sk(A) = (A kB) \ (A kB)�B
K = max{k | (A \ kB) 6= ;}
A =K[
k=0
(Sk(A)� kB)
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Skeletonexample1
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Skeletoniza6onexample2
Elaborazionedisegnalieimmaginiperbioinforma6ca SimonaSchiavi
Applica6ontomedicalimagingVeryusefulinmedicalimagingtocomparepa:entsandhealthycontrolsbrainstructures.
Tract-BasedSpa:alSta:s:csTBSS