04 Morphological Image Processing (Chapter 09)
04 Morphological Image Processing (Chapter 09)
2
a b c
FIGURE 9.1
(a) A set, (b) its
reflection, and
(c)
c) its translat
by z. z2
B̂
B
z1
(B) z
3
Morphological operators
• Change the shape of the foreground regions via
intersection/union operations between a scanning
structuring element and binary image.
• Useful to clean up result from thresholding.
4
Dilation
• Dilation expands the connected sets of a binary image.
• It can be used for
• growing features
5
Ahmed Elgammal, Rutgers
Erosion
• Erosion shrinks the connected sets of a binary image.
• It can be used for
• shrinking features
6
Kristen Grauman, UT-Austin
Structuring elements
• Masks of varying shapes and sizes used to perform
morphology, for example:
A { B = E z ƒ (B
N ) ¨ A Z F
z (9.2-3)
This equation is based on reflecting B about its origin, and shifting this reflection
by z (see Fig. 9.1). The dilation of A by B then is the set of all displacements,
z, such that BN and A overlap by at least one element. Based on this inter-
pretation, Eq. (9.2-3) can be written equivalently as
A { B = E z ƒ [(B)
N ¨ A] 8 A F
z (9.2-4)
Example for Dilation (1D)
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
g ( x) f ( x) SE
Output Image 1
8
Adapted from T. Moeslund
Example for Dilation
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 1 0
10
Example for Dilation
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 1 0 1 1 1 1 1 1
Note that the object gets bigger and holes are filled.
>> help imdilate
16
Salamander notice: The grow
directions will be in this diag.
direction (either in top-right
or bottom-left) only!
In general, if the cross-sectional-area
of the entire thing never surpasses '1'
in both directions for at least one row
and column, then it will be restricted
to growing in one direction.
extreme case:
A | B = 5z ƒ (B)z 8 A6 (9.2-1)
Or, their intersection = (B)z
In words, this equation indicates that the erosion of A by B is the set of all
points z such that B, translated by z, is contained in A. In the following discus-
sion, set B is assumed to be a structuring element. Equation (9.2-1) is the
mathematical formulation of the example in Fig. 9.3(e), discussed at the end of
the last section. Because the statement that B has to be contained in A is
equivalent to B not sharing any common elements with the background, we
can express erosion in the following equivalent form:
A | B = 5z ƒ (B)z ¨ Ac = 6 (9.2-2)
Example for Erosion (1D)
Input image
1 0 0 0 1 1 1 0 1 1
1 1 1
_
- SE
Structuring Element
g ( x ) f ( x )O
Output Image 0
20
Example for Erosion
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0 0 1
25
If the structuring element is just "1" in the
center, this is trivial, output is identity.
Structuring Element 1 1 1
Note that the object gets smaller We can sometimes assume that padding
is of 0s instead, so really, mention it.
>> help imerode 29
extreme case where erosion stops onwards
Remember: If given a problem with numbers, your answer
must use these numbers and be expressed in numbers too.
What if I want 9x9 elements only? Doable in multiple steps... First, remove everything less than 9 with the
same technique we did to get the 15x15 ones, then subtract the 15x15s one from the result, done.
Notice how the circular parts don't
really matter for the dilation step
Problem 9.6
33
Opening
• Erode, then dilate
• Remove small objects, keep original shape
34
Kristen Grauman, UT-Austin
Closing
• Dilate, then erode
• Fill holes, but keep original shape
35
Kristen Grauman, UT-Austin
we want to close this:
37
Hit or Miss
Hit or Miss
Ac (W X)
Ac (W X)
40
(A X) (Ac [W X])
So let's re-visit this. Initially all you knew was opening and closing. Now that you know about
hit-or-miss, don't you think it's more suitable? To be fair, the two methods are very similar.
If you use a structuring element that does
not have the ones in the diagonals, it may
work out here... but not always trustable.
Boundary Extraction
41
An alternative method to extracting boundaries
would be to dilate the original image and remove
the image from it. Is it better? Is it worse? Neither.
Depends on where you want your border, if you
Boundary Extraction want it surrounding the image, do dilation process.
If you want it to be the actual boundary part of the
image, then do the erosion process.
42
The starting point of region fill
must be defined manually.
Then in every step, dilate then subtract (intersect),
repeatedly, until you reach a step that ends up
being no different than the previous one.
Region Filling 43
Region Filling
The algorithm here follows the same
concept used in region filling
45
Extraction of Connected Components
46
Problem 9.17
9.17 Refer to the image and structuring element shown. Sketch what the sets C, D,
E, and F would look like in the following sequence of operations: C = A | B;
D = C { B; E = D { B; and F = E | B. The initial set A consists of all the
image components shown in white, with the exception of the structuring ele-
ment B. Note that this sequence of operations is simply the opening of A by B,
followed by the closing of that opening by B. You may assume that B is just
large enough to enclose each of the noise components.
47
Target is to get the clean rectangle.
Problem 9.17
Ans
48
(a) Write a for loop on the boundary of the image, whenever you hit a
white pixel, do the connected component process starting from it.
Note that one of these border particles may be overlapping with
another which itself wouldn't have been considered a border particle.
Let's assume that both are border particles to simplify the problem.
(c) Knowing they're all same-size, apply connected component on
Problem 9.36 everything and remove the particles of the same size (that have a high
number to avoid anomalies). Could instead do hit-or-miss with the size
of the particle. Same idea kinda, but more automatable, so better.
(b) Subtract (a) and (c) from the image hehe.