Mata kuliah : T0283 - Computer Vision
Tahun
: 2010
Lecture 05
Morphological Filtering
Learning Objectives
After carefully listening this lecture, students will be able
to do the following :
explain various basic principles of morphological based
filtering and demonstrate their application in the
preprocessing stage of image analysis
January 20, 2010
T0283 - Computer Vision
3
Dilation
Y X B X b Bx B X
bB
xX
mask B
X
Y X B
>X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1;
>se=[0 1;1 1];
>Y=imdilate(X,se);
January 20, 2010
T0283 - Computer Vision
4
se1 = structuring elements
0 1 0
1 1 1
0 1 0
se2 = structuring elements
0 0 1
0 1 0
1 0 0
m5 = input image
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
m5 = input image
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
d1 = image
24 24
23 24
23 13
12 19
18 25
d2 = image
17 24
24 5
5 10
10 13
12 19
January 20, 2010
dilation
24 15
14 20
20 22
25 21
25 25
16
22
22
22
9
T0283 - Computer Vision
dilation
5 8 15
8 15 20
14 20 22
20 25 3
25 3 9
5
Dilation on Binary Images
Structuring Element SE
January 20, 2010
T0283 - Computer Vision
6
Erosion
Y=X _ B {x : Bx X }
mask B
Y=X _ B
X
>X=zeros(6,7);X(2:3,4:6)=1;X(4:5,3:5)=1;
>se=[0 1;1 1];
>Y=imerode(X,se);
January 20, 2010
T0283 - Computer Vision
7
se1 = structuring
0 1
1 1
0 1
elements
0
1
0
se2 = structuring elements
0 0 1
0 1 0
1 0 0
m5 = input image
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
m5 = input image
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
e1 = image
17 1
4 5
4 4
4 6
10 11
e2 = image
17 23
23 1
4 6
6 11
11 18
January 20, 2010
erosion
1 1 8
1 7 14
6 13 3
12 2 3
2 2 2
T0283 - Computer Vision
erosion
1 7 14
6 13 16
12 16 21
18 21 2
21 2 9
8
Erosion on Binary Images
Structuring Element SE
January 20, 2010
T0283 - Computer Vision
9
Relationship Between Dilation and
Erosion
(X
_
B)c =Xc
+
^
B
>se1=[0 1;1 1];
>se2=fliplr(flipud(se1));
>X1=imdilate((1-X),se2)
>X2=1-imerode(X,se1)
January 20, 2010
T0283 - Computer Vision
10
Opening
X B (X _ B)
+
B
X
mask B
>X=zeros(6,9);X(3:5,2:4)=1;
>X(3:5,6:8)=1;X(5,5)=1;X(2,7)=1
>se=strel('square',3);
>Y=imdilate(imerode(X,se),se);
%Y=bwmorph(X,’open’);
X B
January 20, 2010
T0283 - Computer Vision
11
Opening : Erosion followed by Dilation
January 20, 2010
T0283 - Computer Vision
12
Closing
X B (X + B) _ B
X
mask B
>X=zeros(6,9);X(3:5,2:4)=1;
>X(3:5,6:8)=1;X(5,5)=1;X(2,7)=1
>se=strel('square',3);
>Y=imerode(imdilate(X,se),se);
%Y=bwmorph(X,’close’);
X B
January 20, 2010
T0283 - Computer Vision
13
Closing : Dilation followed by Erosion
January 20, 2010
T0283 - Computer Vision
14
Relationship Between Opening and
Closing
( X B)C X C Bˆ
( X B)C X C Bˆ
January 20, 2010
>se=strel('line',10,45);
>se2=fliplr(flipud(se));
>X1=~imopen(X,se);
>X2=imclose(~X, se2);
>isequal(X1,X2)
>X1=~imclose(X,se);
>X2=imopen(~X, se2);
>isequal(X1,X2)
T0283 - Computer Vision
15
Hit-Miss Operator
(X _ B1)(Xc _ B2)
X * B=
X
mask B1
January 20, 2010
origin
X*B
mask B2
>bw = [0 0 0 0 0 0;
0 0 1 1 0 0;
0 1 1 1 1 0;
0 1 1 1 1 0;
0 0 1 1 0 0;
0 0 1 0 0 0]
>se = [0 -1 -1;
1 1 -1;
0 1 0];
>bw2 = bwhitmiss(bw,se)
T0283 - Computer Vision
16
Boundary Extraction
X=X-(X _ B)
X
X
>X=zeros(8,11);X(2:4,4:8)=1;X(5:7,2:10)=1;
> se=strel('square',3);
Y=X-imerode(X,se);
%Y=imdilate(X,se)-X;
January 20, 2010
T0283 - Computer Vision
17
Image Example
X
X
January 20, 2010
T0283 - Computer Vision
18
Region Filling
Iterations:
Pseudo
Codes
of
Region
Filling
expansion
stop at the boundary
Y0=P
Yk=(Yk-1B)Xc, k=1,2,3…
Terminate when Yk=Yk-1,output YkX
MATLAB
Codes
of
Region
Filling
January 20, 2010
T0283 - Computer Vision
19
Image Example
Y
Z
>se=strel('square',3);
>r=round(size(Y,1)/2);
> c=round(size(Y,2)/2);
>Z=region_fill(Y,[r,c],se);
January 20, 2010
T0283 - Computer Vision
20
Thinning
x
x
x
x
x
B1
B2
x
B3
x
x
x
x
B4
x
x
x
B5
B6
x
B7
x
x
B8
X0=X
Xk=(…( (Xk-1 B1) B2 … B8)
where
*
X B=X – X
B
Stop the iteration when Xk=Xk-1
January 20, 2010
T0283 - Computer Vision
21
MATLAB Implementation
function y=thinning(x,iter)
se{1}=[-1 -1 -1;0 1 0;1 1 1];
se{2}=[0 -1 -1;1 1 -1;1 1 0];
se{3}=fliplr(rot90(se{1}));
se{4}=flipud(se{2});
se{5}=flipud(se{1});
se{6}=fliplr(se{4});
se{7}=fliplr(se{3});
se{8}=fliplr(se{2});
January 20, 2010
y=x;z=x;
Scheme
A
for i=1:iter
for k=1:8
%y=y&~bwhitmiss(y,se{k});
y=y&~bwhitmiss(z,se{k});
end
z=y;
Scheme
end
B
T0283 - Computer Vision
22
Which One is Right?
Original
image
January 20, 2010
Scheme
A
T0283 - Computer Vision
Scheme
B
23
Result by Using BWMORPH
Scheme
A
Scheme
B
January 20, 2010
> y=bwmorph(x,’thin’,inf);
T0283 - Computer Vision
24
Summary of Morphological Filtering
MATLAB codes
circshift(A,z)
fliplr(flipud(B))
~A or 1-A
A &~B
imdilate(A,B)
imerode(A,B)
imopen(A,B)
imclose(A,B)
January 20, 2010
T0283 - Computer Vision
25
Summary (Con’d)
bwhitmiss(A,B)
A&~(imerode(A,B))
region_fill.m
bwmorph(A,’thin’);
January 20, 2010
T0283 - Computer Vision
26
© Copyright 2026 Paperzz