Professional Documents
Culture Documents
Morphological Image Processing PDF
Morphological Image Processing PDF
- Morphology
A branch of biology that deals with the form and structure of
animals and plants
- Mathematical morphology
A tool to extract image components for representing and describing
region shapes
y E.g.: boundary, skeleton, convex hull
(b) Dilation
- Dilation: grow or thicken an object in a binary image
y Extent of thickening controlled by a structuring element
9-2
y Dilation of image A and structuring element B: A B
A B = {z | ( B ) z A }
with A is
The set of all points z such that the intersection of ( B) z
nonempty
y E.g., a five-pixel-long diagonal line with the origin at the center
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 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 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
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
When the structuring element overlaps 1-valued pixels, the pixel at the
origin is marked 1
y Commutative: A B = B A
9-3
y Associative: A (B C) = (A B) C
* If B = (B1 B2), then A B = A (B1 B2) = (A B1) B2
Dilate A by B1, and then dilate the result by B2 (decomposition)
* E.g., decomposing a structuring element saves computational cost
MATLAB decomposes structuring element automatically
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 1 1 1
1 1 1 1 1 1
9-4
y strel function: create morphological structuring elements
SE = strel(shape, parameters)
* shape: 'arbitrary', 'diamond', 'disk', 'line', 'square', 'rectangle'
(c) Erosion
- Erosion: shrink or thin an object in a binary image
y Extent of shrinking controlled by a structuring element
y Erosion of image A and structuring element B: A \ B
c
A \ B = {z | (B)z A }
c
The set of all points z such that the intersection of (B)z with A is
nonempty
y E.g., a three-pixel-long vertical line with the origin at the center
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 0 0 1 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 1 0 0
0 0 1 1 1 1 1 0 0 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
9-5
When the structuring element overlaps only 1-valued pixels, the pixel at
the origin is marked 1 (i.e., does not overlap background)
y MATLAB: use erosion to eliminate irrelevant details
A = imread('dots.tif'); B = ones(7);
A1 = imerode(A, B); A2 = imdilate(A1, B);
A A1 A2
9-7
(e) Hit-or-miss transformation
- Hit-or-miss transformation: identify special configuration of pixels
A B = (A \ B1) (Ac \ B2)
y E.g., identify 0 1 0
1 1 1
B1 1
1 1 1
B2 1 1
0 1 0 1 1 1
A: A \ B1:
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 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 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 1 1 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 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
Ac: Ac \ B2: A B1:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1 1 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0
1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
9-8
y MATLAB: C = bwhitmiss(A, B1, B2);
- Region filling
Xk = (Xk1 B) Ac k = 1, 2, 3
y X0: a background point inside the object; converged when Xk = Xk1
9-9
y MATLAB
A = im2bw(imread('eye.tif')); B = [0 1 0; 1 1 1; 0 1 0];
Xk = zeros(size(A)); Xk1 = Xk; Xk(85, 70) = 1;
while any(Xk(:) ~= Xk1(:))
Xk1 = Xk;
Xk = imdilate(Xk1, B) & ~A;
end
A1 = Xk | A;
H
y Four structuring elements: Bi, i = 1, 2, 3, 4, (: dont care)
9-12
B B
1 2
B3 B4
D =X
i i C ( A) = U D i
conv , i =1
- Thinning
A ~ B = A (A B) = A (A B)c
where {B} = {B1, B2, , Bn}
y Eight structuring elements: Bi, i = 1, 2, , 8
B1 B
2
B3 B4
B5 B
6
B7 B8
9-13
y Problem: connectivity not guaranteed
- Thickening
A } B = A (A B)
where {B} = {B1, B2, , Bn}
y Eight structuring elements are the same as those of thinning
- Skeletonization
y Repeatedly delete the contour points provided the following
conditions are satisfied
* End points are not deleted
* Connectivity are not broken
* Do not cause excessive erosion of the region
y Algorithm: repeat following steps until no contour points
(1) Delete all contour points according to Definition 1
(2) Delete all contour points according to Definition 2
y Definition 1: right, bottom, and upper left corner contour points
9-14
(a) 2 N(p1) 6 p9 p2 p3
(b) T(p1) = 1
p8 p1 p4
(c) p2 p4 p6 = 0
(d) p4 p6 p8 = 0 p7 p6 p5
* N(p1): number of 1s in the neighborhood of p1
N ( p1 ) = i = 2 pi
9
p1 p1 p1
9-16
p2
p4 p8
p6
(Def. 1) (Def. 2)
9-17
y E.g.:
Image Thinning bwmorph(, 'thin', Inf) bwmorph(, 'skel', Inf)
9-18
- MATLAB morphing function
bwmorph(bw, operation) or bwmorph(bw, operation, n)
y bw: binary image, n: number of repeations of the operation
y operation:
'bothat' Bottom hat operation using a 33 structuring element; use imbothat for other
structuring elements
'erode' Erosion using a 33 structuring element; use imerode for other structuring
elements
'shrink' Shrink objects with no holes to points; shrink objects with holes to rings
'bridge' Connect pixels separated by single-pixel gaps
'fill' Fill in single-pixel holes; use imfill for larger holes
'skel' Skeletonize an image
'clean' Remove isolated foreground pixels
'hbreak' Remove H-connected foreground pixels
'spur' Remove spur pixels
'close' Closing using a 33 structuring element; use imclose for other structuring
elements
'majority' Makes pixel p a foreground pixel if N8(p) 5; otherwise make p a background
pixel
9-19
'thicken' Thicken objects without joining disconnected 1s
'diag' Fill in around diagonally connected foreground pixels
'open' Opening using a 33 structuring element; use imopen for other structuring
elements
'thin' Thin objects without holes to minimally connected strokes; thin objects with
holes to rings
'dilate' Dilation using a 33 structuring element; use imdilate for other structuring
elements
'remove' Remove interior pixels
'tophat' Top hat operation using a 33 structuring element; use imtophat for other
structuring elements
Original
Opening Closing
9-21
- Example: using opening to compensate for nonuniform background
illumination
y Fig. 1: rice grains on nonuniform background (darker towards
bottom), f = imread('rice.tif')
y Fig. 2: simple thresholding: fbw = im2bw(f, graythresh(f)) causes grains
improperly separated at the bottom portion
y Fig. 3: opening with se = strel('disk', 10); fo = imopen(f, se): since the size
of se is set to be larger than the grains, only background remains
y Fig. 4: subtracting from the original f2 = imsubtract(f, fo): results in a
more uniform background
y Fig. 5: thresholding with fbw = im2bw(f2, graythresh(f2)) obtains a better
result
y Subtracting an opened image from the original is called the top-hat
transformation, a single step in Matlab: f2 = imtophat(f, se)
9-22
Fig. 1 Fig. 2 Fig. 3
Fig. 4 Fig. 5
9-23