Morphological Image Processing Basic Algorithms
Morphological Image Processing Basic Algorithms
Morphological
Image Processing:
Basic Algorithms
Preliminaries
When dealing with binary images, one of the principal
applications of morphology is extracting image components
that are useful in the representation and description of
shape.
We consider morphological algorithms for extracting
boundaries, connected components, the convex hull, and the
skeleton of a region. We also develop methods (region
filling, thinning, thickening, and pruning) that are
frequently used in conjunction with these algorithms as pre-
or post-processing steps.
1
4/29/2009
Boundary Extraction
The boundary of a set A, denoted as β(A), can be obtained by first
eroding A by B and then performing the set difference between A and
its erosion as follows:
β ( A) = A − ( A B )
where B is a suitable structuring element.
Set A Structuring
element B
Boundary: set
Erosion of A difference
by B between A and
its erosion
Spring 2009 ELEN 4304/5365 DIP 3
Boundary Extraction
2
4/29/2009
Hole Filling
A hole may be defined as a background region surrounded by a
connected border of foreground pixels.
Let denote byy A a set whose elements are 8-connected boundaries,,
each boundary enclosing a background region (a hole). Given a point
in each hole, the objective is to fill all the holes with ones (for binary
images).
We start from forming an array X0 of zeros (the same size as the array
containing A), except at the locations in X0 corresponding to the given
point in each hole, which is set to one. Then, the following procedure
fills all the holes with ones:
X k = ( X k −1 ⊕ B ) ∩ Ac k = 1, 2,3,...
where B is the symmetric structuring element.
Spring 2009 ELEN 4304/5365 DIP 5
Hole Filling
The algorithm terminates at the iteration step k if Xk = Xk-1.
The set Xk then contains all the filled holes; the union of Xk
and A contains all the filled holes and their boundaries.
The dilation would fill the entire area if left unchecked.
However, the intersection at each step with the complement
of A limits the result to inside the region of interest. This is
an example of how a morphological process can be
conditioned to meet a desired property. In the current
application, it can be called a conditional dilation.
3
4/29/2009
Hole Filling
Complement of A
Set A
S
Structuring
i element
l
Hole Filling
An image that could result from thresholding to 2 levels a scene
containing polished spheres (ball bearings). Dark spots could be
results of reflections. The objective is to eliminate reflections by hole
filling…
filli
A (white) point selected Result of filling that Result of filling all
inside one sphere component the spheres
4
4/29/2009
Set A
5
4/29/2009
Thresholded image
6
4/29/2009
Convex Hull
A set A is said to be convex if the straight line segment joining any
two points in A lies entirely within A. The convex hull H of an
arbitrary set S is the smallest convex set containing S.
The difference H – S is called the convex deficiency of S. The convex
hull and convex deficiency are useful for object description.
Let Bi, i=1,2,3,4 represent the 4 structuring elements. The procedure
consists of implementing the equation:
X ki = ( X k −1 ⊗ B i ) ∪ A i = 1, 2,3, 4 k = 1, 2,3,...
with X 0i = A
When the procedure converges (Xik = Xik-1), we let Di = Xik. The
convex hull of A is then 4
C ( A ) = ∪ Di
i =1
Spring 2009 ELEN 4304/5365 DIP 13
Convex Hull
Therefore, the method consists of iteratively applying the
hit-or-miss transform to A with B1; when no further
changes
g occur,, we perform
p the union with A and call the
result D . The procedure is repeated with B2( applied to A)
1
7
4/29/2009
Convex Hull
Structuring elements: “x” indicates
“do not care” conditions
A set A
Convex Hull
One shortcoming of the procedure is that the convex hull can grow
beyond the minimum dimensions required to guarantee convexity.
One simple approach to reduce this effect is to limit growth such that
it does not extend past the vertical and horizontal dimensions of the
original set.
8
4/29/2009
Thinning
The thinning of a set A by a structuring element B is defined in terms
of the hit-or-miss transform:
A B = A − ( A ⊗ B) = A ∩ ( A ⊗ B)
ⓩ c
{B} = (... ( (ⓩ ) )
SEs:
ⓩ
A A ) B 2 ...ⓩ B n
B1ⓩ
Thinning
The process is to thin A by
one pass with B1, then thin
the result with one pass of Set Sequence of rotated SEs
B2, andd so on, until
til A is
i
thinned with one pass of Bn.
The entire process is repeated
until no further changes
occur.
Results of thinning with
eachh SE one after
ft another
th
9
4/29/2009
Thickening
Thickening is a morphological dual of a thinning and is defined as
B = A ∪ ( A ⊗ B)
c
A
where B is a structuring element suitable for thickening. As in
thinning, thickening can be defined as a sequentional operation:
A {B} = (... ( ( A B1 ) ) )
B 2 ... Bn
The structuring element used for thickening has the same form as one
used for thinning but with all ones and zeros interchanged.
However, the usual procedure is to thin the background of the set to
be processed and then complement the result. Therefore, to thicken a
set A, we form its complement, thin it, and then complement the
result.
Spring 2009 ELEN 4304/5365 DIP 19
Thickening
Depending on the nature of A, the thickening procedure may result in
disconnected points. Therefore, this method is usually followed by
post-processing to remove disconnected points.
Set A Its
complement
Thinned Complement
complement
p of thinningg
of A complement...
10
4/29/2009
Skeletons
A skeleton S(A) of a set A can be viewed as:
a) If z is a point of S(A) and (D)z is the largest disk centered at z and
contained in A,, one cannot find a larger
g disk ((not necessarilyy
centered at z) containing (D)z and included in A. The disk (D)z is
called a maximum disk.
b) The disk (D)z touches the boundary of A at two or more different
places.
The skeleton of A can be expressed in terms of erosions and openings:
K
S ( A) = ∪ Sk ( A)
k =0 Structuring element
Sk ( A ) = ( A kB ) − ( A kB ) B
k successive erosions of A
Spring 2009 ELEN 4304/5365 DIP 21
Skeletons
( A kB ) = (... ( ( A B ) B ) ...) B
K is the last iterative stepp before A erodes to an empty
p y set:
K = max {k | ( A kB ) ≠ ∅}
S(A) can be obtained as the union of the skeleton subsets Sk(A). Also,
we can show that A can be reconstructed from these subsets by:
K
A = ∪ ( S k ( A ) ⊕ kB )
k =0
k successive dilations of A
( A ⊕ kB ) = (... ( ( A ⊕ B ) ⊕ B ) ⊕ ...) ⊕ B
Spring 2009 ELEN 4304/5365 DIP 22
11
4/29/2009
Skeletons
Various positions
of maximum
Set A disks with
centers on the
skeleton of A
Another
maximum disk Complete
on a different skeleton of A
segment of the
skeleton of A
Openings by B
Set differences
Skeletons 2 partial skeletons and final
between 1st
and 2nd
columns
Set A
Erosion 1
of A
Skeleton of
Erosion 2 A (not connected)
of A: next Reconstruc-
erosion ted A
will be ∅ SE
Spring 2009 ELEN 4304/5365 DIP 24
12
4/29/2009
Pruning
Pruning methods are an essential component to thinning and
skeletonizing algorithms since these procedures tend to leave parasitic
components that need to be “cleaned up” by post-processing. We start
with
ith a pruning
i problem
bl andd then
th develop
d l a morphological
h l i l solution.
l ti
A common approach in the automated recognition of printed characters
is to analyze the shape of the skeleton of each character. These
skeletons often are characterized by “spurs” (parasitic components).
Spurs are created during the erosion by non uniformities in the strokes
composing the characters. We develop a morphological technique for
h dli this
handling thi problem,
bl starting
t ti withith the
th assumption
ti that
th t the
th length
l th off a
parasitic component does not exceed a specific number of pixels.
Pruning
A parasitic component
13
4/29/2009
Pruning
The solution is based on suppressing a parasitic branch by successively
eliminating its end point. This also shortens (or eliminates) other
branches in the character. The assumption is that, in the absence of
other
th structural
t t l information,
i f ti any branch
b h with
ith 3 or less
l pixels
i l should
h ld be
b
eliminated. Thinning of an input set A with a sequence of structuring
elements designed to detect only end points achieves the desired result.
Let X1 = ⓩ
A { B}
where {B} is the sequence of structuring elements. This sequence
consists of two different structures, each of which is rotated 900 for a
total of 8 elements.
Applying the equation 3 times yields the set X1 and the next step is to
“restore” the character to its original form but with the parasitic
branches removed.
Pruning
To do this, we first form a set X2 containing all end points in X1:
X 2 = ∪ ( X1 ⊗ Bk )
8
k =1
Bk
where are the same structuring elements. Next step is dilation of the
end points 3 times using set A as a delimiter:
X3 = ( X2 ⊕ H ) ∩ A
where H is a 3x3 structuring element of ones and the intersection with
A as applied after each step. This type of conditional dilation prevents
appearance off non-zero elements
l outside
id the
h region
i off interest.
i
Finally, the union of X3 and X1 yields the desired result:
X 4 = X1 ∪ X 3
14
4/29/2009
Pruning
In more complex situations, X3 sometimes includes the “tips” of some
parasitic branches. This can occur when the end points of these
branches are near the skeleton.
Although, they may be eliminated in X1, these elements may show up
during the dilation since they are valid points in A. The entire parasitic
elements are rarely picked up again since they are usually short
compared to the valid strokes. Therefore, their detection and
elimination is easy since they are disconnected regions.
15
4/29/2009
(
DG( n ) ( F ) = DG(1) DG( n −1) ( F ) )
with
DG( 0) ( F ) = F
Geodesic erosion
Spring 2009 ELEN 4304/5365 DIP 32
16
4/29/2009
Geodesic dilation
Spring 2009 ELEN 4304/5365 DIP 34
17
4/29/2009
Considering these
marker, mask, and
structuring
element…
18
4/29/2009
Opening by reconstruction:
In a morphological opening, erosion removes small objects and the
subsequent dilation attempts to restore the shape of objects that
remain. However,, the accuracy y of this restoration is highly
g y dependent
p
on the similarity of the shapes of the objects and the structuring
element used.
Opening by reconstruction restores exactly the shapes of the objects
that remain after erosion.
Spring 2009 ELEN 4304/5365 DIP 38
19
4/29/2009
n erosions of F by B
n dilations of F by B
20
4/29/2009
21
4/29/2009
22
4/29/2009
X = I − RID ( F )
To obtain an image X with no objects touching the border.
23
4/29/2009
24