Morphological Image Processig Biary dilatio ad erosio Set-theoretic iterpretatio Opeig, closig, morphological edge detectors Hit-miss filter Morphological filters for gray-level images Cascadig dilatios ad erosios Rak filters, media filters, majority filters Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 1
Biary images are commo Biary image processig l Itermediate abstractio i a gray-scale/color image aalysis system Thresholdig/segmetatio Presece/absece of some image property l Text ad lie graphics, documet image processig Represetatio of idividual pixels as 0 or 1, covetio: l foregroud, object = 1 (white) l backgroud = 0 (black) Processig by logical fuctios is fast ad simple Shift-ivariat logical operatios o biary images: morphological image processig Morphological image processig has bee geeralized to gray-level images via level sets Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 2
Shift-ivariace Assume that digital images f [x,y] ad g[x,y] have ifiite support [ x, y] {, 2, 1,0,1,2, } {, 2, 1,0,1,2, }... the, for all itegers a ad b [ ] g[ x, y] f x, y Shiftivariat system [ ] g[ x a, y b] f x a, y b Shiftivariat system Shift-ivariace does ot imply liearity (or vice versa). Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 3
Structurig elemet Neighborhood widow operator { } = f x W f x, y 180 degree rotatio { } x, y y : x, y Π xy structurig elemet ˆ W f x, y { } = { f x + x ʹ, y + yʹ x, yʹ } The hat otatio idicates Π xy Example structurig elemets : : ʹ Π xy upright structurig elemet (i.e., ot rotated!) 5x5 square x x cross y y Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 4
Biary dilatio (expadig foregroud) { } g x, y = OR W f x, y := dilate( f,w ) x f [x, y] Π y xy g[x, y] Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 5
Biary dilatio with square structurig elemet { } g x, y = OR W f x, y := dilate( f,w ) Expads the size of 1-valued objects Smoothes object boudaries Closes holes ad gaps Origial (701x781) dilatio with 3x3 structurig elemet dilatio with 7x7 structurig elemet Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 6
Biary erosio (shrikig foregroud) g x, y = AND W ˆ f x, y { } := erode( f,w ) x f [x, y] Π y xy g[x, y] Caveat: There is aother defiitio of erosio i the literature, which flips the structurig elemet, as for dilatio. The Laguita olie videos use that alterative defiitio. Matlab fuctio imerode uses the defiitio o this slide. To the best of our kowledge, there is o such discrepacy defiig dilatio. Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 7
Biary erosio with square structurig elemet g x, y = AND W ˆ f x, y { } := erode( f,w ) Origial (701x781) erosio with 3x3 structurig elemet erosio with 7x7 structurig elemet Shriks the size of 1-valued objects Smoothes object boudaries Removes peisulas, figers, ad small objects Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 8
Relatioship betwee dilatio ad erosio Duality: erosio is dilatio of the backgroud dilate f,w erode f,w ( ) ( ) = NOT erode NOT f ( ) = NOT dilate NOT f, Wˆ ( ), Wˆ But: erosio is ot the iverse of dilatio f ( ) ( ) x, y erode dilate( f,w ),W dilate erode( f,w ),W Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 9
Example: blob separatio/detectio by erosio Origial biary image Circles (792x892) Erosio by 30x30 structurig elemet Erosio by 70x70 structurig elemet Erosio by 96x96 structurig elemet Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 10
Example: blob separatio/detectio by erosio Origial biary image Circles (792x892) Erosio by disk-shaped structurig elemet Diameter=15 Erosio by disk-shaped structurig elemet Diameter=35 Erosio by disk-shaped structurig elemet Diameter=48 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 11
Example: chai lik fece hole detectio Origial grayscale image Fece (1023 x 1173) Fece thresholded usig Otsu s method Erosio with 151x151 cross structurig elemet Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 12
Set-theoretic iterpretatio Set of object pixels F {( x, y): f ( x, y) = 1} Backgroud: complemet of foregroud set F c {( x, y): f ( x, y) = 0} Dilatio is Mikowski set additio G = F Π xy Cotiuous (x,y). Works for discrete [x,y] i the same way. Commutative ad associative! { ( ) F, ( p x, p ) y Π } xy = ( x + p x, y + p y ): x, y ( p x,p y ) Π xy = F + px,p y ( ) traslatio of F ( by vector p x, p ) y Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 13
Set-theoretic iterpretatio: dilatio G F y x Π xy G = F Π xy { ( ) F, ( p x, p ) y Π } xy = ( x + p x, y + p y ): x, y = F + px,p y ( p x,p y ) Π xy ( ) Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 14
Set-theoretic iterpretatio: erosio G F Mikowski set subtractio Not commutative! Not associative! y x Π xy G = ( p x, p y ) Π xy F + px,p y ( ) = FΘΠ xy Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 15
Opeig ad closig Goal: smoothig without size chage Ope filter Close filter ( ) = dilate erode f,w ( ) = erode dilate f,w ope f,w close f,w ( ( ),W ) ( ),W ( ) Ope filter ad close filter are biased l Ope filter removes small 1-regios l Close filter removes small 0-regios l Bias is ofte desired for ehacemet or detectio! Ubiased size-preservig smoothers close ope f,w ope close f,w ( ( ),W ) ( ( ),W ) ( ) = close ope f,w ( ) = ope close f,w close-ope ad ope-close are duals, but ot iverses of each other. Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 16
Small hole removal by closig Origial biary mask Dilatio 10x10 Closig 10x10 Differece to origial mask Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 17
Morphological edge detectors f x, y dilate( f,w) f erode( f,w) f dilate( f,w) erode( f,w) Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 18
Recogitio by erosio Biary image f ( ) dilate erode( NOT f,w ),W 1400 2000 Structurig elemet W 44 34 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 19
Recogitio by erosio Structurig elemet W 44 34 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 20
Recogitio by erosio Biary image f ( ) dilate erode( NOT f,w ),W 1400 2000 Structurig elemet W 62 18 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 21
Recogitio by erosio Structurig elemet W 62 18 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 22
Hit-miss filter Biary image f ( ( ) & erode( f,w ),W ) dilate erode NOT f,v 1400 2000 Structurig elemet V 62 62 Structurig elemet W 18 18 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 23
Hit-miss filter Structurig elemet V 62 18 Structurig elemet W 62 18 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 24
Morphological filters for gray-level images Threshold sets of a gray-level image f [x,y] ( ) = x, y Τ θ f x, y { : f x, y θ}, < θ < + Recostructio of origial image from threshold sets f x, y { ( )} = sup θ : x, y Τ θ f x, y Idea of morphological operators for multi-level (or cotiuous-amplitude) sigals l Decompose ito threshold sets l Apply biary morphological operator to each threshold set l Recostruct via supremum operatio l Gray-level operators thus obtaied: flat operators! Flat morphological operators ad thresholdig are commutative Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 25
Dilatio/erosio for gray-level images Explicit decompositio ito threshold sets ot required i practice Flat dilatio operator: local maximum over widow W g x, y = max{ W { f x, y }}:= dilate f,w Flat erosio operator: local miimum over widow W ( ) g x, y = mi{ Wˆ { f x, y } }:= erode f,w ( ) Biary dilatio/erosio operators cotaied as special case Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 26
1-d illustratio of erosio ad dilatio Structurig elemet legth = Dilatio Erosio Origial Structurig elemet: horizotal lie Amplitude Sample o. Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 27
Image example Origial 394 x 305 Dilatio 10x10 square Erosio 10x10 square Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 28
Flat dilatio with differet structurig elemets Origial Diamod Disk 20 degree lie 9 poits 2 horizotal lies Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 29
Example: coutig cois thresholded 1 coected compoet Origial 20 coected compoets dilatio thresholded after dilatio Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 30
Example: chai lik fece hole detectio Origial grayscale image Fece (1023 x 1173) Flat erosio with 151x151 cross structurig elemet Biarized by Thresholdig Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 31
Morphological edge detector origial f dilatio g g f g-f g f thresholded Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 32
Beyod flat morphological operators Geeral dilatio operator g x, y = sup α,β Like liear covolutio, with sup replacig summatio, additio replacig multiplicatio Dilatio with uit impulse d α,β does ot chage iput sigal: { f x α, y β + w α,β } = sup = 0 α = β = 0 else α,β { } w x α, y β + f α,β f x, y = sup α,β { f x α, y β + d α,β } Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 33
Fid such that Aswer: w α,β f x, y Flat dilatio as a special case = sup α,β { f x α, y β + w α,β } = dilate f,w w α,β = 0 α,β Π xy else ( ) Hece, write i geeral g!" x, y# $ = sup{ f!" x α, y β # $ + w!" α,β # $ } α,β = dilate f,w ( ) = dilate( w, f ) Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 34
Geeral erosio for gray-level images Geeral erosio operator g x, y = if α,β Dual of dilatio g x, y = if α,β = sup α,β f x +α, y + β w α,β { } = erode( f,w) f x +α, y + β w α,β { } f x +α, y + β + w α,β { } = dilate( f,ŵ) Flat erosio cotaied as a special case Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 35
Cascaded dilatios f dilate( f,w 1 ) dilate ( f,w,w 1 2 ) dilate ( f,w,w,w 1 2 3) dilate dilate( f,w 1 ),w 2 = dilate( f,w) where w = dilate( w 1,w ) 2 Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 36
Cascaded erosios Cascaded erosios ca be lumped ito sigle erosio erode erode( f,w 1 ),w 2 = erode dilate ( f,ŵ 1 ),w 2 = dilate dilate( f,ŵ 1 ),ŵ 2 = dilate( f,ŵ) = erode( f,w) where w = dilate( w 1,w ) 2 New structurig elemet (SE) is ot the erosio of oe SE by the other, but dilatio. Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 37
Fast dilatio ad erosio Idea: build larger dilatio ad erosio operators by cascadig simple, small operators Example: biary erosio by 11x11 widow f x, y f x, y Erosio with 1x3 widow Erosio with 1x3 widow Erosio with 11x11 widow 5 stages g x, y g x, y Erosio with 3x1 widow Erosio with 3x1 widow 5 stages 120 AND per pixel 2x10 = 20 AND per pixel Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 38
Rak filters Geeralisatio of flat dilatio/erosio: i lieu of mi or max value i widow, use the p-th raked value Icreases robustess agaist oise Best-kow example: media filter for oise reductio Cocept useful for both gray-level ad biary images All rak filters are commutative with thresholdig Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 39
Media filter Gray-level media filter Biary images: majority filter Self-duality g x, y = media W f x, y { } g x, y = MAJ W f x, y media f,w majority f,w ( ) = media( f,w ) { } ( ) = NOT majority NOT f := media( f,w ) := majority( f,w ) (,W ) Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 40
Majority filter: example Biary image with 5% Salt&Pepper oise 3x3 majority filter 20% Salt&Pepper oise 3x3 majority filter Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 41
Media filter: example Origial image 5% Salt&Pepper oise 3x3 media filterig 7x7 media filterig Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 42
Example: o-uiform lightig compesatio Origial image 1632x1216 pixels Dilatio (local max) Rak filter 61x61 structurig elemet 10st brightest pixel 61x61 structurig elemet Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 43
Example: o-uiform lightig compesatio Backgroud origial image After global thresholdig Digital Image Processig: Berd Girod, 2013-2018 Staford Uiversity -- Morphological Image Processig 44