Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Prove to yourself that they are not the same thing. Play around
with bwmorph in Matlab.
Opening and Closing
OPENING: The
original image
eroded twice and
dilated twice
(opened). Most
noise is removed
CLOSING: The
original image
dilated and then
eroded. Most
holes are filled.
Boundary Extraction
Dilation
Basic Concepts From Set
theory
Let A and B be sets.
To indicate a is an element of A write a A.
To indicate a is not an element of A write a A.
A is a subset of B, written A B, if for every a A, a B.
The union of A and B, A B x | x A or x B.
The intersection of A and B, A B x | x A and x B.
The complement of A, A c x | x A.
The difference of A and B, A B x | x A and x B.
Examples
A B A B
A A A
B B B
Ac A B A Bc
A A
B
The Cross Product
Let A be a subset of Z 2 .
The reflection of A, written Â, is given by
 x | x -a, where a A.
Here, - a -(a1 , a 2 ) (-a1 ,-a 2 ) A Z 2 .
The translation of A by z, written (A)z , for some z Z 2 is
(A)z x | x a z , for a A.
Special set operations
for morphology
translation reflection
Bˆ {w | w b, for b B}
( A) z {c | c a z , for a A}
Reflection and Translation
Bˆ w w b , for b B
Reflection
Translation
B z c c b z, for b B
Preview
Morphology 形態學
About the form and structure of animals and pl
ants
Mathematical morphology
Using set theory
Extract image component
Representation and description of region shape
Preview (cont.)
Sets in mathematical morphology represent
objects in an image
Example
Binary image: the elements of a set is the
coordinate (x,y) of the pixels, in Z2
Gray-level image: the element of a set is the
triple, (x, y, gray-value), in Z3
Outline
a is not an element of A a A
2 A element condition for set elements
Example:
C w w d , for d D
Set operations
A is a subset of B: every element of A is an element
of another set B A B
Union 聯集 C A B
Intersection 交集 C A B
Mutually exclusive A B
Graphical examples
Graphical examples (cont.)
A w w A
c
A B w w A, w B
Logic operations on binary
images
Functionally complete operations
AND, OR, NOT
A B
A B
BA
Special set operations
for morphology
translation reflection
示例
A B {z | Bˆ A }
z
B
A
A B {z | Bˆ A }
z
A B B A A ( B C ) ( A B) C
The dilation of A by B is the set of all displacements, z, such that B̂ and A
overlap by at least one element.
示例
A B {z | Bˆ A }
z 1 2 3 4 5
1 2 3 4 5
1
1 2
2
3
3 -1 0 1 1
4
4 1
0
5
0
5 -1
6
-1
6
7
7
A
B
A B {z | Bˆ A }
z
The dilation of A by B is the set of all displacements, z, such that B̂ and A
overlap by at least one element.
示例 AB {z | B z A} 2 3 4 5
1
1 2 3 4 5
1
1 2
2
3
3 4 1
1
4 0
0 5
5 -1
6
-1
6
7
7
B
A AB {z | B z A}
The erosion of A by B is the set of all points z such that B, translated
B̂
by z, is contained in A.
1-D Erosion example (5)
1 0 0 0 1 1 1 0 1 1
1 1 1
1-D Erosion example (5)
1 0 0 0 1 1 1 0 1 1
1 1 1
0 0 0 0 1
§ 8.2.2 腐蚀
erosion
示例 AB {z | B z A}
Structuring
Element (B)
A = Object to be eroded
B = Structuring element
Structuring
Element (B)
Dilation
B1
A
A B1
B2
A B2
42
B. Leibe Image Source: R.C. Gonzales & R.E. Woods
Dilation ( 擴張 )
B:structuring
element
A B z ( Bˆ ) A
z
Dilation: another formulation
A B z ( Bˆ ) A A
z
.
Dilation
B1
A
A B1
B2
A B2
45
B. Leibe Image Source: R.C. Gonzales & R.E. Woods
Structuring elements
1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1
1 1 1
1 1 1
1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 0 0 0
0 0 0 1 1 1 1 0 0 0
1 1 1 0 0 0 1 1 1 1 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Application of dilation:
bridging gaps in images
Effects: increase size, fill gap Structuring
element
B:structuring
element
Erosion (cont.)
Ứng dụng phép mởi : Lọc nhiễu ;
test=zeros(10,10);test(2:6,2:4)=1;test(3:5,6:9)=1;test(8:9,4:8)=1;test(4,5)=1
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
sq =
0 1 1 1 0 1 1 1 1 0
1 1 1
0 1 1 1 1 1 1 1 1 0
1 1 1
0 1 1 1 0 1 1 1 1 0
1 1 1
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 0 0
0 0 0 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
sq=ones(3,3) 0 1 1 1 0 1 1 1 1 0
imopen(test,sq) 0 1 1 1 0 1 1 1 1 0
0 1 1 1 0 1 1 1 1 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Opening Operation
A B ( A B) B
or
A B B z B z A
= Combination of all parts of A that can completely contain B
A B c
Ac Bˆ
Properties Opening
1. A B A
2. If C D then C B D B
3. A B B A B
Properties Closing
1. A A B
2. If C D then C B D B
3. A B B A B
Idem potent property: can’t change any more
A()B A()B ( AX ) Ac (W X )
A()B
A()B ( AX ) Ac (W X )
AB1 Ac B2
B B1 B2
(boundary extraction)
( A) A ( AB)
(boundary extraction)
( A) A ( AB)
( A) A ( AB )
( A) ( A B ) A ?
§ 边界提取
8.5.2 vs. 区域填充
区域填充
边界提取:给定区域 R 找边界。 ( A) A ( AB)
(Region filling)
区域填充:给定边界找区域 R 。 X k X k 1 B A 迭代 , 直到收敛 ; 最 R X
c
K A
后
区域填充:设某区域的边界是 A, 设 p 是区域内的一点 ( 不在
边界上 ) 并设 X0=p, 选定一个结构元素 B 则边界 A 所构成的
区域 ( 点的集合 ) 可以通过如下迭代得到:
X 0 p; k 1
X k X k 1 B Ac
Xk==Xk-1?
(收敛?) false
true
R XK A
Stop
X 1 X 0 B Ac
(Region filling)
X 2 X 1 B Ac
X 0 p; k 1
X 3 X 2 B Ac
X k X k 1 B Ac
X 4 X 3 B Ac
Xk==Xk-1?
X 5 X 4 B Ac
(收敛?) false
true X 6 X 5 B Ac
R XK A
X 7 X 6 B Ac
Stop
X 8 X 7 B Ac
X7
为什么最后要并 A R X7 A
呢? R X 7 A
§ 8.5.2 区域填充
(Region filling)
多个区域填充示例
X 0 p; k 1
X k X k 1 B Ac
Assumption: A point inside
Xk==Xk-1? each boundary is given
false
(收敛?)
true
R XK A
Stop
Application of erosion:
eliminate irrelevant detail
Squares of size Erode with
1,3,5,7,9,15 pels 13x13 square
( A B ) z ( B ) z A
c c
z ( B) A
z
c c
z ( B) A
c
z
A B z ( Bˆ ) z A
A Bˆ
c
Application: Boundary extraction
Extract boundary of a set A:
First erode A (make A smaller)
A – erode(A)
= A (A B)
Application: boundary
extraction
original image Using 5x5 structuring element
Outline
Preliminaries
Dilation and erosion
Opening and closing
Hit-or-miss transformation
Some basic morphological algorithms
Extensions to gray-scale images
Opening
Dilation: expands image w.r.t structuring
elements
Erosion: shrink image
erosion+dilation = original image ?
Opening= erosion + dilation
A B (A B) B
Opening (cont.)
Opening (cont.)
Remove
outer opening
noise
closing
Remove
inner
noise
Outline
Preliminaries
Dilation and erosion
Opening and closing
Hit-or-miss transformation
Some basic morphological algorithms
Extensions to gray-scale images
Matlab: Hit-or-miss transformation
010
111
010
Hit-or-Miss transformation
The goal of the "hit-miss" operation is to find pixels x, for which B1x is in A
and where no pixel in B2x is in A (“miss”), thus B2x is in Ac.
The definition of the "hit-miss" operation is:
AB = { x En | B1x A and B2x Ac}
It can be shown that:
AB = ( A B1 ) ( Ac B2 ) = ( A B1 ) - ( A B2r )
B2
Complement Erosion with B2
Boundary extraction
(A) = A - (A B)
B
Hit-or-miss transformation
Find the location of certain shape
X
erosion
Erosion
with (W-X)
Hit-or-miss transformation
Eliminate un-necessary parts
AND
Hit-and-Miss Transform (IV)
Guidelines for Use
The hit-and-miss transform is used to look for
occurrences of particular binary patterns.
It can be used to look for several patterns.
Simply by running successive transforms using different
structuring elements, and then ORing the results together.
The operations of erosion, dilation, opening, closing,
thinning and thickening can all be derived from the hit-
and-miss transform in conjunction with simple set
operations.
Hit-and-Miss Transform (V)
Some structuring elements that can be used for locating various binary
features
1) is used to locate isolated points in a binary image.
2) is used to locate the end points on a binary skeleton.
Note that this structuring element must be used in all its orientations, and
thus the four hit-and-miss passes are required.
3a) and 3b) are used to locate the triple points on a skeleton.
Both structuring elements must be run in all orientations so
eight hit-and-miss passes are required.
Hit-and-Miss Transform (VI)
The triple points (points where three lines meet) of the skeleton
The hit-and-miss transform outputs single foreground pixels at each triple point by
structuring elements 3a) and 3b).
This image was dilated once using a cross-shaped structuring element in
order to mark these isolated points clearly, and this was then ORed with the
original skeleton.
Hit-and-Miss Transform (VII)
The end points of the skeleton
The hit-and-miss transform outputs single foreground pixels at each end point by structuring element 2).
This image was dilated once using a square-shaped structuring element, and this was then ORed with
the original skeleton.
Thinning (I)
Brief Description
Remove selected foreground pixels from binary
images, somewhat like erosion or opening.
Thinning is normally applied only to binary
images.
stop
Region Filling Algorithm
X k ( X k 1 B) A c
where k 1,2,3,...
5. Terminate process if Xk = Xk-1
6. The set union of Xk and A is answer
Region Filling Algorithm
Region Filling Algorithm
p
§ 边界提取
8.5.2 vs. 区域填充
区域填充
边界提取:给定区域 R 找边界。 ( A) A ( AB)
(Region filling)
区域填充:给定边界找区域 R 。 X k X k 1 B A 迭代 , 直到收敛 ; 最 R X
c
K A
后
区域填充:设某区域的边界是 A, 设 p 是区域内的一点 ( 不在
边界上 ) 并设 X0=p, 选定一个结构元素 B 则边界 A 所构成的
区域 ( 点的集合 ) 可以通过如下迭代得到:
X 0 p; k 1
X k X k 1 B Ac
Xk==Xk-1?
(收敛?) false
true
R XK A
Stop
§ 8.5.2 区域填充
单个区域填充示例 X 1 X 0 B Ac
(Region filling)
X 2 X 1 B Ac
X 0 p; k 1
X 3 X 2 B Ac
X k X k 1 B Ac
X 4 X 3 B Ac
Xk==Xk-1?
X 5 X 4 B Ac
(收敛?) false
true X 6 X 5 B Ac
R XK A
X 7 X 6 B Ac
Stop
X 8 X 7 B Ac
X7
为什么最后要并 A R X7 A
呢? R X 7 A
§ 边界提取
8.5.2 vs. 区域填充
区域填充
边界提取:给定区域 R 找边界。 ( A) A ( AB)
(Region filling)
区域填充:给定边界找区域 R 。 X k X k 1 B A 迭代 , 直到收敛 ; 最 R X
c
K A
后
区域填充:设某区域的边界是 A, 设 p 是区域内的一点 ( 不在
边界上 ) 并设 X0=p, 选定一个结构元素 B 则边界 A 所构成的
区域 ( 点的集合 ) 可以通过如下迭代得到:
X 0 p; k 1
X k X k 1 B Ac
Xk==Xk-1?
(收敛?) false
true
R XK A
Stop
§ 8.5.2 区域填充
单个区域填充示例 X 1 X 0 B Ac
(Region filling)
X 2 X 1 B Ac
X 0 p; k 1
X 3 X 2 B Ac
X k X k 1 B Ac
X 4 X 3 B Ac
Xk==Xk-1?
X 5 X 4 B Ac
(收敛?) false
true X 6 X 5 B Ac
R XK A
X 7 X 6 B Ac
Stop
X 8 X 7 B Ac
X7
为什么最后要并 A R X7 A
呢? R X 7 A
§ 8.5.2 区域填充
(Region filling)
多个区域填充示例
X 0 p; k 1
X k X k 1 B Ac
Assumption: A point inside
Xk==Xk-1? each boundary is given
false
(收敛?)
true
R XK A
Stop
Application: region filling
X0 p
X k ( X k 1 B ) A, k 1,2,3,...
Until X k X k 1
Extraction of connected
components (cont.)
original
雞肉
thresholding
erosion
去除小雜訊
(Extraction of connected components)
Region filling
Dilation Conditional dilation
X B Ac
X B X B condition
Extraction of connected components
X B ?
§ 8.5.3 提取连通区域
(Extraction of connected components)
什么是连通区域呢?什么是连通区域的提取?提取连通区域
有什么用途呀?
X k X k 1 B A
Xk==Xk-1?
(收敛?) false
true 流程图
Y XK
Stop
§ 8.5.3 提取连通区域
(Extraction of connected components)
Stop
How to define a
Skeletons?
Set A Maximum disk
1. The largest disk
Centered at a pixel
2. Touch the boundary
of A at two or more
places
Erosion k 次
直到空集合
Problem
The scanned image is not adjusted well
Dilation
Definition
The dilation of A by B is the set
ˆ of all displacements z, such that
( B) z and A overlap by at least one B1
element”. A
A B1
ˆ
( ( B) z is the mirrored version of B,
shifted by z)
Effects
If current pixel z is foreground, set all
pixels under (B)z to foreground. B2
Expand connected components
Grow features
Fill holes
A B2
135
B. Leibe Image Source: R.C. Gonzales & R.E. Woods
Erosion
Definition
“The erosion of A by B is the set
of( B)
all displacements z, such that B1
z
is entirely contained in A”. A
1
Effects
If not every pixel under (B)z is
foreground, set the current pixel z
to background. B2
Erode connected components 2
Shrink features
Remove bridges, branches, noise
136
B. Leibe Image Source: R.C. Gonzales & R.E. Woods