7 Morphological
7 Morphological
7 Morphological
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 1
Binary image processing
n Binary images are common
l Intermediate abstraction in a gray-scale/color image analysis system
• Thresholding/segmentation
• Presence/absence of some image property
l Text and line graphics, document image processing
n Representation of individual pixels as 0 or 1, convention:
l foreground, object = 1 (white)
l background = 0 (black)
n Processing by logical functions is fast and simple
n Shift-invariant logical operations on binary images:
“morphological” image processing
n Morphological image processing has been generalized to
gray-level images via level sets
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 2
Shift-invariance
n Assume that digital images f [x,y] and g[x,y] have infinite support
[ x, y ] ∈{,−2,−1,0,1,2,} × {,−2,−1,0,1,2,}
. . . then, for all integers a and b
f [x - a, y - b ] Shift- g [x - a, y - b ]
invariant
system
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 3
Structuring element
n Neighborhood “window” operator
180 degree rotation “structuring element”
{ } {
W f ⎡⎣ x, y ⎤⎦ = f ⎡⎣ x − x′, y − y′ ⎤⎦ : ⎡⎣ x′, y′ ⎤⎦ ∈Π xy }
The “hat” notation indicates
upright structuring element
(i.e., not rotated!)
y y
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 4
Binary dilation (expanding foreground)
{ }
g ⎡⎣ x, y ⎤⎦ = OR ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := dilate ( f ,W )
y
f [x, y] P xy g[x, y]
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 5
Binary dilation with square structuring element
{ }
g ⎡⎣ x, y ⎤⎦ = OR ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := dilate ( f ,W )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 6
Binary erosion (shrinking foreground)
y
f [x, y] P xy g[x, y]
Caveat: There is another definition of erosion in the literature, which flips the structuring element, as for dilation.
The Lagunita online videos use that alternative definition. Matlab function imerode uses the definition on this slide.
To the best of our knowledge, there is no such discrepancy defining dilation.
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 7
Binary erosion with square structuring element
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 8
Relationship between dilation and erosion
(
f ⎡⎣ x, y ⎤⎦ ≠ erode dilate ( f ,W ) ,W )
≠ dilate ( erode ( f ,W ) ,W )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 9
Example: blob separation/detection by erosion
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 10
Example: blob separation/detection by erosion
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 11
Example: chain link fence hole detection
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 12
Set-theoretic interpretation
Continuous (x,y).
n Set of object pixels
{( x, y ) : f ( x, y ) = 1}
Works for discrete [x,y]
F≡ in the same way.
= {( x + p , y + p ) : ( x, y ) ∈F,( p , p ) ∈Π }
x y x y xy
= F+ p , p
( )
( )
px , p y ∈Π xy
x y
translation of F by vector px , p y ( )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 14
Set-theoretic interpretation: dilation
F
x
y P xy
G = F ⊕ Π xy
= {( x + p , y + p ) : ( x, y ) ∈ F,( p , p ) ∈Π }
x y x y xy
= F+
( p ,p )
( p , p )∈Π
x y xy
x y
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 15
Set-theoretic interpretation: erosion
F x
y P xy
G
Not commutative!
Not associative!
Minkowski set subtraction
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 16
Opening and closing
n Goal: smoothing without size change
Open filter
( )
n
(
close − open ( f ,W ) = close open ( f ,W ) ,W )
open − close ( f ,W ) = open ( close ( f ,W ) ,W )
n close-open and open-close are duals, but not inverses of each other.
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 17
Small hole removal by closing
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 18
Morphological edge detectors
f éë x, y ùû (
dilate f ,W ¹ f ) (
erode f ,W ¹ f ) ( ) (
dilate f ,W ¹ erode f ,W )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 20
Recognition by erosion
Binary image f
1400
2000
Structuring
44
element W
34
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 21
Recognition by erosion
Structuring
44
element W
34
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 22
Recognition by erosion
Binary image f
1400
2000
Structuring
62
element W
18
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 23
Recognition by erosion
Structuring
62
element W
18
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 24
Hit-miss filter
Binary image f
1400
2000
Structuring Structuring
62
62
element V element W
18 18
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 25
Hit-miss filter
Structuring
62
element V
18
Structuring
62
element W
18
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 26
Morphological filters for gray-level images
{ (
f ⎡⎣ x, y ⎤⎦ = sup θ : ⎡⎣ x, y ⎤⎦ ∈Τθ f ⎡⎣ x, y ⎤⎦ )}
n Idea of morphological operators for multi-level
(or continuous-amplitude) signals
l Decompose into threshold sets
l Apply binary morphological operator to each threshold set
l Reconstruct via supremum operation
lGray-level operators thus obtained: flat operators
è Flat morphological operators and thresholding are commutative
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 28
Dilation/erosion for gray-level images
n Explicit decomposition into threshold sets not required in practice
n Flat dilation operator: local maximum over window W
{ {
g ⎡⎣ x, y ⎤⎦ = max W f ⎡⎣ x, y ⎤⎦ }} := dilate( f ,W )
n Flat erosion operator: local minimum over window W
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 29
1-d illustration of erosion and dilation
Structuring element length =
——Dilation
——Erosion
——Original
Structuring element:
horizontal line
Amplitude
Sample no.
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 30
Image example
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 31
Flat dilation with different structuring elements
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 32
Example: counting coins
Original 20 connected
components
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 33
Example: chain link fence hole detection
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 34
Morphological edge detector
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 36
Beyond flat morphological operators
n General dilation operator
{ } {
g ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + w ⎡⎣α , β ⎤⎦ = sup w ⎡⎣ x − α , y − β ⎤⎦ + f ⎡⎣α , β ⎤⎦
α ,β α ,β
}
n Like linear convolution, with sup replacing summation, addition replacing multiplication
n Dilation with “unit impulse”
⎧0 α =β =0
d ⎡⎣α , β ⎤⎦ = ⎨
⎩−∞ else
does not change input signal:
{
f ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + d ⎡⎣α , β ⎤⎦
α ,β
}
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 37
Flat dilation as a special case
n Find w éëa , b ùû such that
{ }
f ⎡⎣ x, y ⎤⎦ = sup f ⎡⎣ x − α , y − β ⎤⎦ + w ⎡⎣α , β ⎤⎦ = dilate ( f ,W )
α ,β
n Answer:
⎧⎪0 ⎡⎣α , β ⎤⎦ ∈Π xy
w ⎡⎣α , β ⎤⎦ = ⎨
⎪⎩−∞ else
{
g !" x, y #$ = sup f !" x − α , y − β #$ + w !"α , β #$
α ,β
}
= dilate ( f , w) = dilate ( w, f )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 38
General erosion for gray-level images
n General erosion operator
n Dual of dilation
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 39
Cascaded dilations
f dilate ( f , w1 ) dilate ( f , w1 , w2 )
where w = dilate ( w1 , w2 )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 40
Cascaded erosions
n Cascaded erosions can be lumped into single erosion
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 41
Fast dilation and erosion
n Idea: build larger dilation and erosion operators by cascading simple, small
operators
n Example: binary erosion by 11x11 window
Erosion with … Erosion with
1x3 window 1x3 window
Erosion with
5 stages
11x11 window
Erosion with … Erosion with
3x1 window 3x1 window
5 stages
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 42
Rank filters
n Generalisation of flat dilation/erosion: in lieu of min or max value in window,
use the p-th ranked value
n Increases robustness against noise
n Best-known example: median filter for noise reduction
n Concept useful for both gray-level and binary images
n All rank filters are commutative with thresholding
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 44
Median filter
n Gray-level median filter
{ }
g ⎡⎣ x, y ⎤⎦ = median ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := median ( f ,W )
n Binary images: majority filter
{ }
g ⎡⎣ x, y ⎤⎦ = MAJ ⎡⎣W f ⎡⎣ x, y ⎤⎦ ⎤⎦ := majority ( f ,W )
n Self-duality
median ( f ,W ) = − ⎡⎣ median ( − f ,W ) ⎤⎦
(
majority ( f ,W ) = NOT ⎡⎣ majority NOT ⎡⎣ f ⎤⎦ ,W ⎤⎦ )
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 45
Majority filter: example
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 46
Median filter: example
Original image 5% ‘Salt&Pepper’ noise 3x3 median filtering 7x7 median filtering
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 47
Example: non-uniform lighting compensation
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 48
Example: non-uniform lighting compensation
Digital Image Processing: Bernd Girod, © 2013-2018 Stanford University -- Morphological Image Processing 49