Professional Documents
Culture Documents
09 Morph
09 Morph
09 Morph
Morphing
B
A
z = (z1,z2)
(A)z B̂
Logical Operations*
A ⊕ B = z Bˆ z ∩ A ≠ φ
A ⊕ B = z [ Bˆ z ∩ A] ⊆ A
A ⊕ B = z Bˆ z ∩ A ≠ φ
φ = Empty set
Dilate means “extend”
A = Object to be dilated
B = Structuring element
Example: Application of Dilation
>> B=[0 1 0; 1 1 1; 0 1 0]
B= Remember! Dilation is an
0 1 0 operation that “grows” or
1 1 1
0 1 0 “thickens” objects in a binary
>> A=imread('fig0905.tif'); image. The specific manner and
>> A2=imdilate(A,B); extent of this thickening is
>> imshow(A);
>> figure;imshow(A2); controlled by a shape refer to as
a structuring element
Example: Application of Dilation
Remember! Dilation is an
operation that “grows” or
“thickens” objects in a binary
image. The specific manner and
extent of this thickening is
controlled by a shape refer to as
a structuring element.
Erosion Operation
A B = z (B )z ⊆ A
The Erosion of A by B is the set of all points z such that B,
translated by z is contained in A.
A B
A = Object to be eroded
B = Structuring element
Erosion Operation
MatlabàErosion: The
value of the output pixel
is the minimum value of
all the pixels in the input
pixel's neighborhood. In a
binary image, if any of
the pixels is set to 0, the
output pixel is set to 0.
Example: Application of Dilation and Erosion
( A B ) c = Ac ⊕ Bˆ
where c = complement
Proof:
( A B ) = z (B )z ⊆ A
c c
= z (B )z ∩ A = φ
c c
= z (B )z ∩ Ac ≠ φ
= A ⊕ Bˆ
c
Opening Operation
A o B = ( A B) ⊕ B
or
A o B = ∪ (B )z (B )z ⊆ A
= Combination of all parts of A that can completely contain B
(A • B) c
= Ac o Bˆ
Properties Opening
1. A o B ⊆ A
2. If C ⊂ D then C o B ⊂ D o B
3. ( A o B ) o B = A o 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
Example: Application of Morphological Operations
Finger print enhancement
f=imread('fig911.tif');
se=strel('square',3)
fo=imopen(f,se);
imshow(fo);
foc=imclose(fo,se);
figure;imshow(foc);
Erosion of A by B1 Erosion of Ac by B2
Hit--or
Hit or--Miss Transformation (cont.)
Matlab command
C=bwhitmis(A,B1,B2);
Example:
>>f=imread(‘Fig0913.tif’);
Original Boundary
image
Boundary Extraction
β(A) = A − A B
A=imread('fig914.jpg');
B=strel('square',3)
AeB=imerode(A,B);
Bon=A-AeB;
imshow(Bon);
Original Boundary
image
Region Filling
X k = ( X k −1 ⊕ B ) ∩ Ac
X-ray image
of bones
Thresholded
image
Connected
components
(Images from Rafael C.
Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Convex Hull
Convex hull has no concave part.
Convex hull
4
Algorithm: C ( A) = D i where D i = X conv
i
i =1
X ki = X k −1 * B i ∪ A, i = 1,2,3,4 convergence
Example: Convex Hull
X ki = X k −1 * B i ∪ A,
i = 1,2,3,4
Thinning
A ⊗ B = A − ( A * B)
= A ∩ ( A * B )c
Make an object
thinner.
Thickening
A B = A ∪ ( A * B)
A {B} = ((...(( A 1
B) 2
B )...) n
B )
However, we can do as
follow:
1. C=Ac
2. Thin C
3. Form Cc
and K = max k ( A kB ) ≠ φ
Skeletons
Pruning
X 1 = A ⊗ {B} = thinning
8
X2 = k
( X 1 * B ) = finding end points
k =1
X 4 = X 1 ∪ X 3 = Pruned result
Example: Pruning
Original
image
After
Thinning End
3 times points
Dilation
of end Pruned
points result
Summary of Binary Morphological Operations
x = don’t care
Gray--Scale Dilation
Gray
1-D Case f ⊕ b = max{f ( s − x ) + b( x ) | ( s − x ) ∈ D f and x ∈ Db }
2-D Case
f ⊕ b = max{f ( s − x, t − y ) + b( x, y ) | ( s − x ), (t − y ) ∈ D f ; ( x, y ) ∈ Db }
Gray--Scale Dilation (cont.)
Gray
Original image Reflection
Subimage of B
+
Max
Moving
window
Structuring
element B
Min
Moving
window
Structuring
element B
Darker Brighter
After erosion
Gray--Scale Opening
Gray
f o b = ( f − b) ⊕ b
Reduce dark
Reduce white objects
objects
Gray--scale Morphological Smoothing
Gray
Smoothing: Perform opening followed by closing
h = f − ( f o b)
h = f − ( f o b)
Example: Texture Segmentation Application
Small
blob
Size distribution
Original image graph
Example: Granulometry
Example: Granulometry
Matlab:: morphological processing
Matlab
Matlab:: morphological processing
Matlab
Matlab:: Create Structural Element
Matlab
SE=strel(‘shape’, parameter)
>>se=strel('diamond',3)
0 0 0 1 0 0 0
0 0 1 1 1 0 0
0 1 1 1 1 1 0
1 1 1 1 1 1 1
0 1 1 1 1 1 0
0 0 1 1 1 0 0
0 0 0 1 0 0 0
Size distribution
graph
Matlab:: morphological processing
Matlab
bwmorph
Morphological operations on binary images
Syntax
BW2 = bwmorph(BW,operation)
BW2 = bwmorph(BW,operation,n)
Matlab:: bwmorph
Matlab
Matlab:: bwmorph
Matlab
Size distribution
Original image graph
Matlab:Label connected components in binary image
bwlabel
Syntax
L = bwlabel(BW,n)
[L,num] = bwlabel(BW,n)
Description
L = bwlabel(BW,n) returns a matrix L, of the same size as BW, containing labels for
the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-
connected objects and 8 specifies 8-connected objects; if the argument is omitted, it
defaults to 8.
The elements of L are integer values greater than or equal to 0. The pixels labeled 0
are the background. The pixels labeled 1 make up one object, the pixels labeled 2
make up a second object, and so on.
Examples
>> f=imread('rice.png');
>> imshow(f);
>> figure;imhist(f);
>> figure;imshow(f>140);
>> se=strel('disk',10);
>> fo=imopen(f,se);
>> figure;imshow(fo);
>> f2=imsubtract(f,fo);
>> figure;imshow(f2);
>> figure;imhist(f);
>> figure;imshow(f2>50);