CVIP Chapter Three
CVIP Chapter Three
CoSc4113
Chapter 3
Morphological Image Processing
1
Contents
Morphological Image processing
▪ Dilation and Erosion
▪ Opening And Closing
▪ Application of Opening And Closing
▪ Gray-scale Morphology
▪ Gray-scale Morphology Applications
▪ Basic Morphological Algorithms
22
Morphological Image processing
The word morphology refers to form and structure of an
object.
“Morphology“ – a branch in biology that deals with the form
and structure of animals and plants.
“Mathematical Morphology” – as a tool for extracting
image components, that are useful in the representation and
description of region shape.
The language of mathematical morphology is – Set theory.
Unified and powerful approach to numerous image processing
problems.
In binary images , the set elements are members of the 2-D
integer space – Z . where each element (x,y) is a coordinate of a
black (or white) pixel in the image.
3
Effect of Some Morphological Processing
00010010001000
00011110001000
00010010001000
5
Thresholding
Binary images can be obtained by thresholding.
Assumptions for thresholding:
Object region of interest has intensity distribution different
from background.
Object pixels likely to be identified by intensity alone:
intensity > a
intensity < b
a < intensity < b
Works OK with flat-shaded scenes or engineered scenes.
Does not work well with natural scenes.
6
Mathematic Morphology
Morphological processes on images are used to extract
image components that are useful in the representation
and description of region shape, such as
boundaries extraction
skeletons
convex hull
morphological filtering
Thinning
Thickening
pruning
7
Basic Concepts in Set Theory
Subset
Union
Intersection
disjoint / mutually exclusive
Complement
Difference
Reflection
Translation
8
Logic Operations
The principal logic operations used in image processing
are:
1. AND,
2. OR,
3. NOT (COMPLEMENT)
Logic operations are preformed on a pixel by pixel basis between
corresponding pixels (bitwise).
Other important logic operations :
1. XOR (exclusive OR),
2. NAND (NOT-AND)
9
Possible Operations
10
Operations in Image Morphology
Mathematical morphology consists of two basic operations
dilation
erosion
and several composite relations that can be made of the above
opening
closing
conditional dilation
…
11
Pixels and neighborhoods
In many algorithms, not only the value of a particular pixel, but
also the values of its neighbors are used when processing that
pixel.
The two most common definitions for neighbors are the 4-
neighbors and the 8-neighbors of a pixel.
12
Structuring Element
The two most common structuring elements (given a
Cartesian grid) are the 4-connected and 8-connected sets,
N4 and N8.
13
Structuring Elements, Hits & Fits
B Structuring Element
This equation is based on obtaining the reflection of B about its origin and
shifting this reflection by z.
The dilation of A by B is the set of all displacements z, such that and A
overlap by at least one element. Based on this interpretation the previous
equation can be rewritten as:
18
Dilation
Dilation expands the connected sets of 1s of a binary image.
It can be used for
growing features
19
Dilation
➢ The basic effect of the operator on a binary image is to gradually
enlarge the boundaries of regions of foreground pixels (i.e.
white in the example).
➢ Thus areas of foreground pixels grow in size while holes within
those regions become smaller.
20
Dilation - How It Works
➢ To compute the dilation of a binary input image by this
structuring element, we consider each of the background pixels in
the input image in turn.
➢ For each background pixel (which we will call the input pixel)
we superimpose the structuring element on top of the input image
so that the origin of the structuring element coincides with the
input pixel position.
➢ If at least one pixel in the structuring element coincides
with a foreground pixel in the image underneath, then the
input pixel is set to the foreground value.
➢ If all the corresponding pixels in the image are
background, however, the input pixel is left at the
background value.
21
Dilation
Dilation of image Aby structuring element Bis given by A B
The structuring element s is positioned with its origin at (x, y)
of image A and the new pixel value of A is determined using the
rule:
1if B hits A
g(x, y) =
0 otherwise
22
Dilation – With Substitution Example
23
Dilation – With Vector Addition Example
0 1 2 0 1
0 0 1 0 1 1
0
1 1 0 0 0 0
1
2 0 0 0
B
Structural Element
A
➢ Where are 1s of A A(0,1) and A(1,0)
➢ Where are 1s of B B(0,0) and B(0,1)
0 1 2
➢ Then Add each one of 1s in Awith all 1s of B
0 0 1 1
➢ A(0,1) + B(0,0) C(0,1)
1 1 1 0
➢ A(0,1) + B(0,1) C(0,2)
2 0 0 0
➢ A(1,0) + B(0,0) C(1,0)
➢ A(1,0) + B(0,1) C(1,1) C
24 ➢ The four coordinates of the Output image will be 1s and the rest will be 0s.
Dilation Example
26
Purpose of Dilation
Dilation can repair breaks
28
Erosion
The basic effect of the operator on a binary image is to erode
away the boundaries of regions of foreground pixels (i.e.
white pixels in the example). Thus areas of foreground pixels
shrink in size, and holes within those areas become larger. Effect of
erosion using a 3×3 square structuring element
29
How Erosion Works
➢ To compute the erosion of a binary input image by this
structuring element, we consider each of the foreground pixels
in the input image in turn. For each foreground pixel (which
we will call the input pixel) we superimpose the structuring
element on top of the input image so that the origin of the
structuring element coincides with the input pixel coordinates.
➢ If for every pixel in the structuring element, the
corresponding pixel in the image underneath is a
foreground pixel, then the input pixel is left as it is.
➢ If any of the corresponding pixels in the image are
background, however, the input pixel is also set to
background value.
30
Erosion
Erosion of image Aby structuring element B is given by A B
The structuring element B is positioned with its origin at (x, y)
of the image A and the new pixel value of A is determined using
the rule:
1if Bfits A
g(x, y) =
0 otherwise
31
Erosion
This equation indicates that the erosion of Aby Bis the set of
all points z such that B, translated by z, is combined in A.
32
Erosion– With Substitution Example
33
Erosion– With Shifting Example
➢ Slide B over A staring from the first pixel
1 1 1 1 1 1 and :
1 1 0 1 1 0 ➢ Whenever B fully matches with part of
0 1 1 1 A, set the value of A that is aligned to the
B focal point of B to 1 and move on.
0 1 0 0 Structural Element
➢ Whenever B does not fully match with
A part of A, set the value of A that is
aligned to the focal point of B to 0 and
move on.
1 1 1 1
0 1 1 1 0 1 1 1
1 1 0 1
1 1 0 1 1 1 0 1
0 1 1 1 0 1 0 0
0 1 1 1 0 1 1 1
0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0
Step 1
0 1 0 0
Step 2 Step 3
No match match 1 0 0 0 0
No match
0 0
Changing the Structural Element (B) with a different C
34 formation will result in a totally different final image.
Erosion Example
After erosion
Original
with a disc of
image
radius 10
36
Purpose of Erosion
Erosion can split apart joined objects
38
Erosion & Dilation: eliminating irrelevant detail
39
Example: Dilation and Erosion using same
Structuring Element
Original
Dilated Image
SE= 5 X 5
Eroded Image
40
Exercise
➢ Do erosion of A by the different structural elements B1 and B2 separately
and observe the variation in the final result
B1
Structural Element
B2
Structural Element
A
41
Opening And Closing
Opening – smoothes contours , eliminates projection
These operations are can be applied few times, but has effect
only once
42
Opening And Closing
Opening –
First – erode A by B, and then dilate the result by B
In other words, opening is the unification of all B objects
Entirely Contained in A
Opening: roll B around the inside of A.
43
Opening And Closing…cont
Closing –
First – dilate A by B, and then erode the result by B
In other words, closing is the group of points, which the
intersection of object B around them with object A– is not
empty
Closing: roll B around the outside of A.
44
45
46
Useful: open & close
47
47 47
Application of Opening and
Closing: Morphological Filtering
Morphological operations can be used ta construct filters
similar in concept to the spatial filters
Here the noise manifests it-self as light elements on a
dark background and as dark elements on the light
components of the fingerprint.
49
49
Filtering by Opening and Closing Operation
The two operations just described constitute the opening of A by B.
We note In Fig (d) that the net effect of opening was to eliminate
virtually all noise components in both the background and the
Fingerprint itself. However, new gaps between the fingerprint ridges
were created.
To counter this undesirable effect, we perform a dilation on the opening,
as shown in Fig.(e).
Most of the breaks were restored, but the ridges were thickened, a
condition that can be remedied by erosion.
The result, shown in Fig. (f), constitutes the closing of the opening in
Fig. (d).This final result is remarkably clean of noise specks, but it has
the disadvantage that some of the print ridges were not fully repaired,
and thus contain breaks. This is not totally unexpected, because no
conditions were built into the procedure for maintaining connectivity
this can be solved by skeleton concept.
50
50
Use of opening and closing for morphological
filtering
51
51
Gray-scale Morphology
In grayscale morphology is applied to gray scale images, a pixel is compared to those
pixels surrounding it in order to keep the pixels whose values are the smallest (in the
case of an erosion) or the largest (in the case of a dilation).
The basic morphological operations of dilation, erosion, opening and closing can also be
applied to gray images.
Use grayscale morphology functions used to
▪ filter or smooth the pixel intensities of an image. Applications include noise filtering, uneven
background correction, and gray-level feature extraction.
▪ alter the shape of regions by expanding bright areas at the expense of dark areas and vice
versa.
▪ smooth gradually varying patterns and increase the contrast in boundary areas.
The following gray-level morphology functions are applied in image processing:
▪ Erosion
▪ Dilation
▪ Opening
▪ Closing
▪ Proper-opening
▪ Proper-closing Reading Assignment
▪ Auto-median
52
52
Gray-scale Dilation
The gray-scale dilation of a gray-scale image f by a structure element b is defined as:
where Db is the domain of the structuring element b. This process operates in the same way
as the spatial convolution.
The figure below shows the result of dilating a gray image using a 3×3b square
structuring element.
We can see that gray-scale dilation produces the following: 1. Bright and slightly blurred image. 2.
Small, dark details have been reduced.
53
53
(a) Original gray image. (b) Dilated image.
Gray-scale Erosion
The gray-scale erosion of a gray-scale image f by a structure element b is defined as:
The next figure shows the result of eroding a gray image using a 3×3 square structuring
element.
We can see that gray-scale erosion produces the following:1. Dark image. 2. Small, bright details
were reduced.
54
54
((a) Original gray image. (b) Eroded image.
Gray-scale Opening
The opening and closing of gray-scale images have the same form as in
the binary images:
▪ Opening :
▪ Closing:
The figure below shows the result of opening a gray image.
Note the decreased sizes of the small, bright details, with no appreciable effect on the
darker gray levels.
55
55
(a) Original gray image. (b) Opened image.
Gray-scale Closing
The opening and closing of gray-scale images have the same form as in
the binary images:
▪ Opening :
▪ Closing:
The figure below shows the result of closing a gray image.
Note the decreased sizes of the small, dark details, with relatively little effect on the
bright features.
56
56
(a) Original gray image. (b) Closed image.
Gray-Scale Morphology Applications
Morphological smoothing
Smoothing is obtained by performing a morphological opening
followed by a closing as shown in the figure below.
57
57
Gray-Scale Morphology Applications..cont
Morphological gradient
is produced from subtracting an eroded image from its dilated version.
It is defined as:
The resulted image has edge-enhancement characteristics, thus morphological gradient
can be used for edge detection as shown in the figure below.
58
58
(a) Original gray image. (b) Morphological gradient.
Basic Morphological Algorithms
1. Boundary Extraction
2. Region Filling
3. Extraction of Connected Components
4. Convex Hull
5. Thinning
Reading Assignment
6. Thickening
7. Skeletons
59
Boundary Extraction
First, erode Aby B, then make set difference between A and
the erosion
The thickness of the contour depends on the size of
constructing object – B
60
Boundary Extraction
61
Region Filling
This algorithm is based on a set of dilations,
complementation and intersections
p is the point inside the boundary, with the value of 1
X(k) = (X(k-1) xor B) conjunction with complemented A
The process stops when X(k) = X(k-1)
The result that given by union of Aand X(k), is a set contains
the filled set and the boundary
62
Region Filling
63
Extraction of Connected Components
64
Extraction of Connected Components
65
End of Chapter 3
66