2009-05-13 Digital Image Processing Achim J. Lilienthal AASS Learning Systems Lab, Dep. Teknik Room T1209 [email protected] Marco Trincavelli Part 6: Binary Image Operations and Morphological Image Processing Course Book Chapter 2.5 + 9
2009-05-13
Digital Image Processing
Achim J. Lilienthal
AASS Learning Systems Lab, Dep. Teknik
Room T1209
Marco Trincavelli
Part 6: Binary Image Operations and
Morphological Image Processing
Course Book Chapter 2.5 + 9
Achim J. Lilienthal
1. Binary Image Operations
z Basic Concepts of Set Theory (Recap)
z Logic Operations (Recap)
z Neighbourhood Relations
z Distance Measures
2. Basic Morphological Operators
z Dilation, Erosion
z Opening, Closing
z Hit-or-Miss Transform
Contents
Achim J. Lilienthal
3. Morphological Algorithms
z Boundary Extraction, Region Filling
z Extraction of Connected Components
z Convex Hull
z Thinning, Thickening
z Skeletonization
Contents
Achim J. Lilienthal
Binary Image Operations
Contents
Achim J. Lilienthal
Binary Image Operations1
z Basic Concepts of Set Theory
union of A and B:
C=AB={c|cA or cB}
intersection of A and B:
C=AB={c|cA and cB}
disjoint/mutually exclusive: AB=
AB
AB
Achim J. Lilienthal
Logic Operations Involving Binary Images1
A B
NOT A A AND B
A OR B A XOR B
XOR
Achim J. Lilienthal
Neighbourhood Relations1
z Neighbourhood Relations Between Pixels
y a pixel has 4 or 8 neighbours in 2D
depending on the neighbour definition:
x 4-neighborhood N4(p)
each neighbor must share
an edge with the pixel
x ND(p): diagonal neighbors of p
x 8- neighborhood N8(p)
each neighbor must share
an edge or a corner with the pixel
Achim J. Lilienthal
z Adjacency
y 4-adjacency
x p and q are similar, and q is in N4(p)
y 8-adjacency
x p and q are similar, and q is in N8(p)
y m-adjacency (mixed)
x p and q are similar, and either
• q is in N4(p), or
• q is in ND(p) and
the set N4(p)N4(q) does not contain similar pixels
x "include diagonal pixels if not 4-connected anyway"
Neighbourhood Relations1
Achim J. LilienthalAchim J. Lilienthal
Neighbourhood Relations1
z Adjacency
y 4-adjacency
x p and q are similar, and q is in N4(p)
y 8-adjacency
x p and q are similar, and q is in N8(p)
y m-adjacency (mixed)
x p and q are similar, and either
• q is in N4(p), or
• q is in ND(p) and
the set N4(p)N4(q) does not contain similar pixels
y two image subsets S1 and S2 are adjacent if ... ?
Achim J. Lilienthal
z Adjacency
y 4-adjacency
x p and q are similar, and q is in N4(p)
y 8-adjacency
x p and q are similar, and q is in N8(p)
y m-adjacency (mixed)
x p and q are similar, and either
• q is in N4(p), or
• q is in ND(p) and
the set N4(p)N4(q) does not contain similar pixels
y two image subsets S1 and S2 are adjacent if
some pixel in S1 is adjacent to some pixel in S2.
Neighbourhood Relations1
Achim J. Lilienthal
z Path Between p and q
y two pixels p=(x0,y0) and q=(xn,yn) are connected if there
is a sequence of adjacent pixels between p and q (a path)
y length of the path is n
Neighbourhood Relations1
p=(x0,y0)
q=(xn,yn)
(x1,y1)
(xn-1,yn-1)
adjacent
adjacent
...
Achim J. Lilienthal
z Path Between p and q
y 4-, 8-, or m-path (depending on the type of adjacency)
Neighbourhood Relations1
4-path 8-path
Achim J. Lilienthal
z Connected Components
y S: subset of pixels in an image
y pixels p and q are connected in S if there is a path
between them consisting only of pixels from S
y for any pixel p in S, the set of pixels in S connected to p
is called a connected component of S
y every two pixels in a connected
component are connected
y S is a connected set if it has only
one connected component
(a region of an image)
Neighbourhood Relations1
8-connected set
Achim J. LilienthalAchim J. Lilienthal
Binary Image Operations1
z Boundary
y consider a region R (= connected set)
y boundary := ?
x discuss appropriate definitions
Achim J. Lilienthal
Binary Image Operations1
z Boundary
y consider a region R (= connected set)
y boundary := the set of pixels
with one or more neighbours not in R
y
Achim J. Lilienthal
Basic Morphological Operators
Contents
Achim J. Lilienthal
z Mathematical Morphology
y mathematical tools to deal with form and structure
y "the language of mathematical morphology is set theory"
x sets 2 in case of binary images
x sets 3 in case of gray-scale images
z Application
y pre-processing: noise-filtering, shape simplification, …
y enhancing object structure: skeletonization, convex hull, …
y segmentation: watershed
y quantitative description: area, perimeter, …
2 Basic Morphological Operators
Achim J. Lilienthal
Basic Morphological Operators
z Dilation And Erosion
y defined with respect to a structuring element (SE)
z Structuring Element (Kernel)
y small set to probe the image
y defined by an origin …
y … and its shape and size
z Basic Idea
y check a condition for the structuring element
y output pixel = 1 if condition is satisfied, 0 otherwise
2
Achim J. Lilienthal
Basic Morphological Operators
})ˆ(|{ ABzBA z
z Dilation ( + )
y does the mirrored SE
(set B) touch the set A?
y grows objects
y dilation of A by B (SE):
all z such that
B hits A when B is translated by z
(i.e. the origin of B is at z)
})ˆ(|{ AABzBA z or
B
^
^
2
Achim J. Lilienthal
Basic Morphological Operators
z Dilation ( + ), Example
2
B
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion (⊖)
y does the SE
(set B) fit into the set A?
y shrinks objects
y erosion of A by B (SE):
all z such that B
translated by z is contained in A
(i.e. the origin of B is at z)
2
B
})(|{ ABzBA z
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
B
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Erosion Example
2
BA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation
y bridging gaps
z Erosion
y eliminating small details
z Structuring Element
y specifies the structure of elements ...
x ... that are removed by erosion
x ... that are filled by dilation
y is typically symmetric about the origin BB ˆ
2
B
Achim J. Lilienthal
Basic Morphological Operators
z Different Structuring Elements, Dilation
2
Achim J. Lilienthal
Basic Morphological Operators
z Different Structuring Elements, Dilation
2
Achim J. Lilienthal
Basic Morphological Operators
z Different Structuring Elements, Erosion
2
Achim J. Lilienthal
Basic Morphological Operators
z Different Structuring Elements, Erosion
2
Achim J. Lilienthal
Basic Morphological Operators
z Dilation and Erosion Duality
y dilation and erosion are duals of each other
with respect to set complementation and reflection
2
BABA CC ˆ
BAA B CBA
Achim J. Lilienthal
Basic Morphological Operators
z Dilation and Erosion Duality
y dilation and erosion are duals of each other
with respect to set complementation and reflection
2
BABA CC ˆ
CAA B̂ BAC ˆ
Note: set B is
reflected twice!
Achim J. Lilienthal
Basic Morphological Operators
z Opening (∘) = Erosion Followed by Dilation
y smoothes wrt to the foreground (the contour objects)
x breaks "narrow" isthmuses
x eliminates "thin" protrusions
y "narrow" / "thin" in relation to the SE
y geometric interpretation
x "structuring element rolling inside"
2
BBABA
ABBBA zz
Achim J. Lilienthal
Basic Morphological Operators
z Geometric Interpretation of Opening
y union of all (B)z where (B)z fits into A
2
ABBBA zz
ABBwwBA zz
Achim J. Lilienthal
Basic Morphological Operators
z Opening
2
A A⊖B
Achim J. Lilienthal
Basic Morphological Operators
z Opening
2
A⊖B A∘B
Achim J. Lilienthal
Basic Morphological Operators
z Opening
2
A A⊖B
Achim J. Lilienthal
Basic Morphological Operators
z Opening
2
A⊖B A∘B
Achim J. Lilienthal
Basic Morphological Operators
z Opening
y eliminating irrelevant detail …
... without affecting the remaining parts
2
erosion: SE=square of size 13x13
dilation: SE=square of size 13x13
BBABA
Achim J. Lilienthal
Basic Morphological Operators
z Closing () = Dilation Followed by Erosion
y smoothes with respect to the background
x fuses "narrow" breaks
x eliminates "small" holes
y "narrow" / "thin" in relation to the SE
y geometric interpretation
x "structuring element rolling outside"
2
BBABA
ABBBA zz
C
Achim J. Lilienthal
Basic Morphological Operators
z Geometric Interpretation of Closing
y complement of the union of all (B)z where (B)z fits into AC
2
Czz ABBBA
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A A+ B
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A+ B AB
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A+ B AB
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A A+ B
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A+ B AB
Achim J. Lilienthal
Basic Morphological Operators
z Closing
2
A+ B AB
Achim J. Lilienthal
Properties of Opening and Closing
z Opening
y A∘B is a subset of A ("opening of A is A")
y if C is a subset of D then C∘B is a subset of D∘B
y repeated openings have no effect (idempotent)
z Duality
y see next slide ...
2
BDBCDC
BABBA
Achim J. Lilienthal
Properties of Opening and Closing
z Closing
y A is a subset of AB ("closing of A is A")
y if C is a subset of D then CB is a subset of DB
y repeated closings have no effect (idempotent)
z Opening and Closing Duality
y duals with respect to complementation and reflection
2
BDBCDC
BABBA
BABA CC ˆ
Achim J. Lilienthal
Properties of Opening and Closing
z Opening and Closing Duality
y duals with respect to complementation and reflection
2
A A∘B (A∘B)C
AC ACB
BB ˆ
2009-05-13
Digital Image Processing
Achim J. Lilienthal
AASS Learning Systems Lab, Dep. Teknik
Room T1209
Marco Trincavelli
Part 6: Binary Image Operations and
Morphological Image Processing
Course Book Chapter 2.5 + 9
Achim J. Lilienthal
Basic Morphological Operators
z Application: Filtering (Opening + Closing)
y eliminating noise with little morphological distortion
2
original image
Achim J. Lilienthal
Basic Morphological Operators
z Application: Filtering (Opening + Closing)
1. erosion: A⊖B
2
Achim J. Lilienthal
Basic Morphological Operators
z Application: Filtering (Opening + Closing)
2. dilation: (A⊖B) + B = A∘B
2
Achim J. Lilienthal
Basic Morphological Operators
z Application: Filtering (Opening + Closing)
3. dilation: (A∘B) + B
2
Achim J. Lilienthal
Basic Morphological Operators
z Application: Filtering (Opening + Closing)
4. erosion: ((A∘B) + B)⊖B = (A∘B)B
2
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
y find pixels with a specific neighbourhood
("template matching")
y composite structuring element:
object part (B1) and background part (B2)
y does B1 fit the object while simultaneously
B2 misses the object, i.e. B2 fits the background
y with B = (B1,B2); B1: object (X), B2: local background (W – X)
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
A=XYZ
B1 B2
A⊖B1
YX
Z
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
AC
B1 B2
AC⊖B2
YX
Z
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
AC
B1 B2
AC⊖B2
YX
Z
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
B1 B2
A⊛X=(A⊖B1)(Ac⊖B2)A=XYZ
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform (⊛)
y find pixels with a specific neighbourhood
("template matching")
y composite structuring element:
object part (B1) and background part (B2)
y does B1 fit the object while simultaneously
B2 misses the object, i.e. B2 fits the background
y with B = (B1,B2); B1: object (X), B2: local background (W – X)
21)( BABABA C
)ˆ()( 21 BABABA
Achim J. Lilienthal
Basic Morphological Operators2
z Applications of the Hit-or-Miss Transform
y locate isolated foreground pixels
x no neighbouring foreground pixels
y locate foreground endpoints
x one or zero neighbouring foreground pixels
y locate foreground contour points
x pixels having at least one neighbouring background pixel
y locate multiple foreground points
x pixels having more than two neighbouring foreground pixels
Achim J. Lilienthal
Basic Morphological Operators2
4-connected isolated points (A⊛B)
SE for 4-connected isolated points
z Hit-or-Miss Transform to Find Isolated Points
y how should the HMT structuring elements look like?
input image4-connected isolated points (A⊛B)
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform to Find Isolated Points
input image 4-connected isolated points (A⊛B)
B1 B2
SE for 4-connected isolated points
Achim J. Lilienthal
Basic Morphological Operators2
4-connected isolated points (A⊛B)
SE for 4-connected isolated points
z Hit-or-Miss transform to find 4-connected endpoints
y how should the HMT structuring elements look like?
input image endpoints
Achim J. Lilienthal
Basic Morphological Operators2
z Hit-or-Miss Transform to Find Foreground Endpoints
input image endpoints (A⊛Ba A⊛Bb A⊛Bc A⊛Bd)
B1 Ba2 Bb
2 Bc2 Bd
2
SEs for 4-connected endpoints
Achim J. Lilienthal
Morphological Algorithms
Contents
Achim J. Lilienthal
Morphological Algorithms3
z Boundary Extraction
y (A) boundary of A
y boundary extraction
x erosion and set difference )()( BAAA
8-connected boundary boundary 4-connected with AC
4-connected boundary boundary 8-connected with AC
Achim J. Lilienthal
Morphological Algorithms3
z Region Filling
y start with a point p = X0 inside the boundary
y iterative dilation, complementation, and intersection
y terminate if Xk = Xk-1
y final result:
set union Xk-1 A
! intersection with Ac limits
the result to inside the
region of interest
c
kk ABXX 1
A Ac
black = background
Achim J. Lilienthal
Morphological Algorithms3
z Region Filling
A
B
X0 X1 X2
…
X6 X7 X8
X7 A
Ac
Achim J. Lilienthal
z Region Filling
y requires a seed pixel inside the boundary
seed
one filled final resultwhite discs with
black spots
not straightforward to automatise
Morphological Algorithms3
Achim J. Lilienthal
Extraction of Connected Components3
z Extraction of the Connected Component Y in A
y start with a point p = X0 inside Y
y iterative dilation and intersection with A
y terminate if Xk = Xk-1
y final result:
set union Y=Xk-1=Xk
! intersection with A keeps
the result to the object Y
in A
ABXX kk 1
X0
Achim J. Lilienthal
Extraction of Connected Components3
B
X0
X1 X2
X3 X4 Y
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Convex Hull – Definitions
y convex region R
x straight line from x1 to x2 is in R for any x1, x2R
y convex hull H of a region R
x smallest convex set containing R
y convex deficiency D
x H – R
R: green
H: green + brown
D: brown
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
y set of Structuring Elements
x can contain don’t care symbols
x typically obtained from one
structuring element by rotation
y iterative Hit-or-Miss transform
x iteratively apply HMT with Bi to A
x simplified HMT where no background match is required
x stop if convergence is achieved ( Di) if Xk = Xk-1
y final result
x union of the resulting Di
Bi
don’t care
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
y initialisation
y iterative Hit-or-Miss transform with Bi
y convergence and final result
AX i 0
iI
i
DAC 1
)(
i
k
i
k
i
k
i XXXD1
,
,...3,2,1,,...,2,1,1 kIiABXX i
k
i
k
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
Xi0=A X1
4
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
X14 X2
2 X38 X4
2
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
Achim J. Lilienthal
Morphological Algorithms – Convex Hull3
z Obtaining a Convex Region
y problem
x C(A) is convex but not necessarily minimal in size
y limit growth to the original dimensions
x horizontally and vertically or more complex (diagonal, ...)
Achim J. Lilienthal
Morphological Algorithms – Thinning3
z Thinning – Idea
y finding structural elements to preserve
x topology, end points
y iterative use of Hit-or-Miss transform – one thinning pass:
y simplified HMT where no background match is required
z Alternative Expression for Symmetric Thinning
y thin by a suitable sequence of B={B1,B2,...,Bn}
y repeat whole sequence until no further changes occur
)( BAABA cBAABA )(
nBBBABA ...... 21
Achim J. Lilienthal
z Thinning
B1 B2 B3 B4 B5 B6 B7 B8
A A ⊗ B1
3 Morphological Algorithms – Thinning
Achim J. Lilienthal
z Thinning
A ⊗ B2 A ⊗ B3
A ⊗ B4 A ⊗ B5
B2
B4 B5
B3
Morphological Algorithms – Thinning3
Achim J. Lilienthal
z Thinning
A ⊗ B6 A ⊗ B7
A ⊗ B8 A ⊗ B1
B1
B6
B8
B7
Morphological Algorithms – Thinning3
Achim J. Lilienthal
z Thinning
... A ⊗ B4 A ⊗ B5
A ⊗ B6
B4 B5
B6... no further changes
Morphological Algorithms – Thinning3
Achim J. Lilienthal
z Morphological Dual of Thinning
y definition: iterative use of Hit-or-Miss transform
y can also be defined as a sequential operation
y can be implemented as thinning the background
x A Ac
x thin Ac Ac ⊗ {B}
x complement the result A {B} = (Ac ⊗ {B})c
)( BAABA
nBBBABA ...... 21
Morphological Algorithms – Thickening3
Achim J. Lilienthal
A Ac
Ac ⊗{B}
(Ac ⊗{B})c
disconnected points removed
Morphological Algorithms – Thickening3
Achim J. Lilienthal
z Skeletonization Algorithms
y residual of openings (Serra[1982]) GW pp. 543
y Distance Transformation
x detecting ridges in distance map of the boundary points
Morphological Algorithms – Skeletonization3
Achim J. Lilienthal
Distance Transform
z Distance Transform
y representation of distances in an image
y transformation from binary image to DT image
y distance transform as grey-level landscape
x each object pixel is labelled
with the distance to its closest pixel in the background
y skeleton = maxima in the distance
to the border
3
Achim J. Lilienthal
Distance Transform – Examples3
z Distance Transform Examples – Euclidean Distance
Achim J. Lilienthal
city block chess board
Distance Transform – Examples3
Achim J. Lilienthal
city block chess board
Distance Transform – Examples3
Achim J. Lilienthal
0 0 0 0 0 0 0 1 1 2
0 0 0 0 0 0 1 1 2 2
0 0 0 0 0 1 1 2 2 3
0 0 0 0 1 1 2 2 3 3
0 0 0 1 1 2 2 3 3 4
0 0 1 1 2 2 3 3 4 4
0 1 1 2 2 3 3 4 4 5
0 1 2 2 3 3 4 4 5 5
0 1 2 3 3 4 4 5 5 6
0 1 2 3 4 4 5 5 6 6
0 0 0 0 0 0 0 1 2 3
0 0 0 0 0 0 1 2 3 4
0 0 0 0 0 1 2 3 4 5
0 0 0 0 1 2 3 4 5 6
0 0 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
city block chess board
Distance Transform – Examples3
Achim J. Lilienthal
Distance Transform3
z Distance Transform as Grey Level Landscape
Achim J. Lilienthal
z Distance Transform for Path Planning
y used for robot navigation
y constrained DT
x find shortest path
x avoid obstacles
x basic DT + obstacle regions
Distance Transform – Applications3
Achim J. Lilienthal
obstaclep0constrained distance transform
Distance Transform for Path Planning3
Achim J. Lilienthal
z Hill Climbing Using Steepest Path
Distance Transform for Path Planning3
Achim J. Lilienthal
3
z Distance Transform for Thickness Measurements
y DT gives a rough measure
of the object’s thickness
at each point
y the highest distance label
in the object
gives the maximum thickness
Distance Transform – Applications
Achim J. Lilienthal
z Distance Transform, Sensitivity to Noise
3 Distance Transform
Achim J. Lilienthal
z Skeletonization Algorithms
y residual of openings (Serra[1982]) GW pp. 543
y Distance Transformation
x detecting ridges in distance map of the boundary points
y Voronoi diagram
x partitioning of a plane
into convex polygons
such that each polygon
contains one generating point
and every point in a polygon
is closer to its generating point
than to any other
Morphological Algorithms – Skeletonization3
Achim J. Lilienthal
1. Binary Image Operations
z Basic Concepts of Set Theory (Recap)
z Logic Operations (Recap)
z Neighbourhood Relations
z Distance Measures
2. Basic Morphological Operators
z Dilation, Erosion
z Opening, Closing
z Hit-or-Miss Transform
Contents
Achim J. Lilienthal
3. Morphological Algorithms
z Boundary Extraction, Region Filling
z Extraction of Connected Components
z Convex Hull
z Thinning, Thickening
z Skeletonization
Contents
2009-05-13
Digital Image Processing
Achim J. Lilienthal
AASS Learning Systems Lab, Dep. Teknik
Room T1209
Marco TrincavelliMarco Trincavelli
Course Book Chapter 2.5, 9
Part 3: Binary Image Operations and
Morphological Image Processing
Thank you!