Image Processing
Morphological image
processing
Outline
2
What is Mathematical Morphology?
Background Notions
Introduction to Set Operations on Images
Basic operation
Erosion, Dilation, Opening, Closing, Hit-or-Miss
Algorithms
Morphological operations on gray-level images
Morphology
3
Morphology, in biology, is the study of the size,
shape, and structure of animals, plants, and
micro-organisms and the relationships of their
internal parts.
Morphology, in linguistics, is the study of the
internal construction of words
Mathematical morphology?
Mathematical morphology
4
Mathematical Morphology was founded in the mid-sixties in France
George Matheron and Jean Serra are two founders of mathematical
morphology
Study of geometry of porous media
Mathematical morphology is well established discipline in applied
mathematics and image analysis
International Symposium on Mathematical Morphology
Mathematical morphology
5
The theory for the analysis of spatial structures
Analysis of shapes and form of objects
It is based on set theory, integral geometry and
lattice algebra
Structuring elements
Mathematical morphology framework is used for:
Image filtering (shape simplification, enhancing object
structure,...)
Image segmentation (watersheds)
Image measurements (area, perimeter, granulometry)
Pattern recognition
Texture analysis
Quick Example
Image after segmentation Image after segmentation and
morphological processing
6
7
Morphological Image Processing…
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
pruning
Morphological Image Processing
8
“Mathematical Morphology” – as a tool for extracting image
components, that are useful in the representation and description
of region shape.
Morphological image processing (or morphology) describes a
range of image processing techniques that deal with the shape
(or morphology) of features in an image
Morphological operations are typically applied to remove
imperfections introduced during segmentation, and typically
operate on bi-level images
The language of mathematical morphology is – Set theory.
Unified and powerful approach to numerous image processing
problems.
9
Z2 and Z3
set in mathematic morphology represent
objects in an image
binary image (0 = white, 1 = black) : the element
of the set is the coordinates (x,y) of pixel belong
to the object Z2
gray-scaled image : the element of the set is
the coordinates (x,y) of pixel belong to the object
and the gray levels Z3
Basic Concepts in Set Theory
Subset
Union
Intersection
disjoint / mutually exclusive
Complement
Difference
Reflection
Translation
11
Basic Set Theory
12
Reflection and Translation
} ,|{ˆ Bfor bbwwB
} ,|{)( Afor azaccA z
Logic Operations Involving
Binary Pixels and Images
13
The principal logic operations used in image processing
are: AND, OR, NOT (COMPLEMENT).
These operations are functionally complete.
Logic operations are preformed on a pixel by pixel basis between
corresponding pixels (bitwise).
Other important logic operations :
XOR (exclusive OR), NAND (NOT-AND)
Logic operations are just a private case for a binary set operations, such :
AND – Intersection , OR – Union, NOT-Complement.
14
Example
Structuring Element (SE)
15
Small set used to probe the image under study
For each SE, define an origin:
the origin of the SE is in point p
The shape and size must be adapted to geometric
properties for the objects
SE can be described in many different ways!
Information needed:
Position of origin for SE
Position of elements belonging to SE
16
Structuring Element (SE)
OBS!
Matlab assumes that the center of the structuring elements is its origin
Structuring Elements, Hits &
Fits
B
AC
Structuring Element
Fit: All on pixels in the
structuring element cover
on pixels in the image [A]
Hit: Any on pixel in the
structuring element covers
an on pixel in the image [B]
All morphological processing operations are based
on these simple ideas 17
Fundamental Operations
Fundamentally morphological image
processing is very like spatial filtering
The structuring element is moved across
every pixel in the original image to give a
pixel in a new processed image
The value of this new pixel depends on the
operation performed18
Five binary morphological operators
⊖ Erosion
⊕ Dilation
◦ Opening
• Closing
⊗ Hit-or-Miss transform19
⊖Erosion
Does the structuring element fit the set?
Erosion of a set X by structuring element B,
: all x in X such that B is in X when
origin of B is x
Gonzalez-Woods:
Shrink the object
20
Erosion
otherwise 0
fits if 1),(
fsyxg
Erosion of image f by structuring element s is
given by f s
The structuring element s is positioned with
its origin at (x, y) and the new pixel value is
determined using the rule:
21
Erosion Example
Original image Erosion by 3*3
square structuring
element
Erosion by 5*5
square structuring
element
22
Erosion Example 2
Original
image
After erosion
with a disc of
radius 10
After erosion
with a disc of
radius 20
After erosion
with a disc of
radius 5
23
Erosion can split apart
joined objects
Erosion can strip away
extrusion
Erosion shrinks objects
How is Erosion used?
24
Does the structuring element hit the set?
Dilation of a set X by structuring element B,
: all x in X such that the reflection of B
hits X when origin of B is x
Gonzalez-Woods:
Enlarge the object
⊕ Dilation
25
Dilation of image f by structuring element s is
given by f s
The structuring element s is positioned with
its origin at (x, y) and the new pixel value is
determined using the rule:
⊕ Dilation
otherwise 0
hits if 1),(
fsyxg
26
⊕ Dilation Example
Original image Dilation by 3*3
square structuring
element
Dilation by 5*5
square structuring
element
27
Dilation Example
Structuring element
Original image After dilation
28
Dilation can repair
breaks
Dilation can repair
intrusions
Dilation enlarges objects
How is Dilation used?
29
⊖ Erosion - properties
It is commutative
It is increasing, i.e.,
if A ⊂ C, then A ⊖ B ⊂ C ⊖ B
If the origin belongs to the structuring element B,
then the erosion is anti-extensive, i.e., A ⊖ B ⊂ A
It is distributive over set intersection, i.e.,
(A1 ∩ A2) ⊖ B = (A1 ⊖ B) ∩ (A2 ⊖ B)
It is translation invariant
30
⊕ Dilation - properties
It is commutative
It is increasing, i.e.,
if A ⊂ C, then A ⊕ B ⊂ C ⊕ B
If the origin belongs to the structuring element B,
then it is extensive A ⊂ A ⊕ B
It is distributive over set union, i.e.,
(A1 ∪ A2) ⊕ B = (A1 ⊕ B) ∪ (A2 ⊕ B)
It is translation invariant
31
Erosion - Dilation duality
Erosion and dilation are dual with respect to complementation and
reflection
32
Compound Operations
More interesting morphological operations
can be performed by performing
combinations of erosions and dilations
The most widely used of these compound
operations are:
Opening
Closing
33
The opening of image f by structuring
element s, denoted f ○ s is simply an erosion
followed by a dilation
f ○ s = (f s) s
◦ Opening
Original shape After erosion After dilation
(opening) 34
◦ Opening
35
erosion followed by dilation, denoted ∘
eliminates protrusions
breaks necks
smoothes contour
BBABA )(
◦ Opening
erosion followed by dilation, denoted ∘
eliminates protrusions
breaks necks
smoothes contour
36
BBABA )(
◦ Opening Example
Original
Image
Image
After
Opening
37
38
◦ Opening
BBABA )(})(|){( ABBBA zz
The closing of image f by structuring element
s, denoted f • s is simply a dilation followed by
an erosion
f • s = (f s)s
• Closing
Original shape After dilation After erosion
(closing) 39
• Closing
dilation followed by erosion, denoted •
smooth contour
fuse narrow breaks and long thin gulfs
eliminate small holes
fill gaps in the contour
40
BBABA )(
41
• Closing
BBABA )(
42
Properties
Opening(i) AB is a subset (subimage) of A(ii) If C is a subset of D, then C B is a subset of D B(iii) (A B) B = A B
Closing(i) A is a subset (subimage) of AB(ii) If C is a subset of D, then C B is a subset of D B(iii) (A B) B = A B
Note: repeated openings/closings has no effect!
• Closing Example
Original
Image
Image
After
Closing
43
Morphological Processing
Example: filtering
erosion
opening
opening
+ dilation
opening + closing
Morphological Algorithms
Using the simple technique we have looked at
so far we can begin to consider some more
interesting morphological algorithms
Hit-or-miss transform
Boundary extraction
Region filling
Extraction of connected components
Thinning/thickening
Skeletonisation
Pruning
45
⊗ Hit-or-miss transformation
The hit-or-miss transform is a general binary
morphological operation that can be used to look
for particular patterns of foreground and
background pixels in an image.
The hit-and-miss transform is a basic tool for
shape detection.
To detect a shape:
Hit object
Miss background
46
⊗ Hit-or-miss transformation
The structural elements (SE) used for Hit-or-
miss transforms are an extension to the ones
used with dilation, erosion etc.
The SE contain both foreground and background
pixels, rather than just foreground pixels, i.e. both
ones and zeros.
If the SE covers something which matches
the content of the SE it is a hit, otherwise it is
a miss
47
)()()( 21 BABABX
⊗ Hit-or-miss transformation
Transformation that involves two structuring
elements
First has to fit with the object while,
simultaneously, the second has to fit the
background
First has to hit the object while, simultaneously,
second has to miss it
A ⊗ B = (A ⊖ B1) ∩ (AC ⊖ B2)
Composite SE B = (B1,B2): Object part (B1) and
background (B2)48
⊗ Hit-or-miss transformation
Alternative:
A ⊗ B = (A ⊖ B1) ∩ (AC ⊖ B2)
= (A ⊖ B1) ∩ (A ⊕ ˆB2)C
= (A ⊖ B1) \ (A ⊕ ˆB2)
B1 and B2 share the same origin and are
disjoint sets
49
⊗ Hit-or-miss transformation
50
Structuring
elements
Extracting the boundary (or outline) of an object is often
extremely useful
The boundary can be given simply as
β(A) = A – (AB)
Boundary Extraction
51
Boundary Extraction Example
Original Image Extracted Boundary
A simple image and the result of performing
boundary extraction using a square 3*3
structuring element
52
Given a pixel inside a boundary, region filling
attempts to fill that boundary with object
pixels (1s)
Region Filling
Given a point inside
here, can we fill the
whole circle?
53
The key equation for region filling is
Where X0 is simply the starting point inside
the boundary, B is a simple structuring
element and Ac is the complement of A
This equation is applied repeatedly until Xk is
equal to Xk-1
Region Filling
.....3,2,1 )( 1 kABXX c
kk
54
Region Filling Step By Step
Region Filling Example
Original Image One Region
Filled
All Regions
Filled
56
57
Extraction of connected
components
.....3,2,1 )( 1 kABXX kk
58
Example
Convex hull
i
iDAC
4
1)(
,...3,2,1 and 4,3,2,1 )( kiABXX ii
k
i
k
A set A is said to
be convex if the
straight line
segment joining
any two points in
A lies entirely
within A.
59
Thinning
The thinning of a set A by a structuring element B, can
be defined by terms of the hit-and-miss transform:
A more useful expression for thinning A symmetrically is
based on a sequence of structuring elements:
{B}={B1, B2, B3, …, Bn}
Where Bi is a rotated version of Bi-1. Using this concept
we define thinning by a sequence of structuring
elements:
Thinning cont…
The process is to thin by one pass with B1 ,
then thin the result with one pass with B2, and
so on until A is thinned with one pass with Bn.
The entire process is repeated until no further
changes occur.
Each pass is preformed using the equation:
62
Thinning
cBAA
BAABA
)(
)(
Thickening
Thickening is a morphological dual of
thinning.
Definition of thickening .
As in thinning, thickening can be defined as a
sequential operation:
the structuring elements used for thickening
have the same form as in thinning, but with
all 1’s and 0’s interchanged.
Thickening - cont
A separate algorithm for thickening is often used in practice, Instead the usual procedure is to thin the background of the set in question and then complement the result.
In other words, to thicken a set A, we form C=Ac , thin C and than form Cc.
depending on the nature of A, this procedure may result in some disconnected points. Therefore thickening by this procedure usually require a simple post-processing step to remove disconnected points.
Thickening- example
We will notice in the next example that the
thinned background forms a boundary for the
thickening process, this feature does not
occur in the direct implementation of
thickening
This is one of the reasons for using
background thinning to accomplish
thickening.
Thickening example
Thinning and Thickening
67
Skeleton
The notion of a skeleton S(A) of a set A is
intuitively defined, we deduce from this figure
that:
a) If z is a point of S(A) and (D)z is the largest disk
centered in z and contained in A (one cannot
find a larger disk that fulfils this terms) – this
disk is called “maximum disk”.
b) The disk (D)z touches the boundary of A at two
or more different places.
Skeleton The skeleton of A is defined by terms of erosions and
openings:
with
Where B is the structuring element and indicates
k successive erosions of A:
k times, and K is the last iterative step before A erodes to an empty
set, in other words:
in conclusion S(A) can be obtained as the union of
skeleton subsets Sk(A).
BkBAkBAASk )()()(
70
Skeletons
K
kk ASAS
0
)()(
})(|max{ kBAkK
))((0
kBASA k
K
k
71
Skeleton
A can be also reconstructed from subsets
Sk(A) by using the equation:
Where denotes k successive
dilations of Sk(A) that is:
73
Pruning
}{1 BAX
AHXX )( 23
314 XXX
)( 1
8
12
k
kBXX
H = 3x3 structuring element of 1’s
74
75
76
77
Gray-Scale Images
In gray scale images on the contrary to binary
images we deal with digital image functions of
the form f(x,y) as an input image and b(x,y) as a
structuring element.
(x,y) are integers from Z*Z that represent a
coordinates in the image.
f(x,y) and b(x,y) are functions that assign gray
level value to each distinct pair of coordinates.
For example the domain of gray values can be
0-255, whereas 0 – is black, 255- is white.
Gray-Scale Images
Dilation – Gray-Scale
Equation for gray-scale dilation is:
Df and Db are domains of f and b.
The condition that (s-x),(t-y) need to be in the domain of f and x,y in the domain of b, is analogous to the condition in the binary definition of dilation, where the two sets need to overlap by at least one element.
Dilation – Gray-Scale (cont)
We will illustrate the previous equation in terms of
1-D. and we will receive an equation for 1 variable:
The requirements the (s-x) is in the domain of f and x is in the domain of b imply that f and b overlap by at least one element.
Unlike the binary case, f, rather than the structuring element b is shifted.
Conceptually f sliding by b is really not different than b sliding by f.
Dilation – Gray-Scale (cont)
The general effects of performing dilation on
a gray scale image is twofold:
1. If all the values of the structuring elements are
positive than the output image tends to be
brighter than the input.
2. Dark details either are reduced or elimanted,
depending on how their values and shape relate
to the structuring element used for dilation
Dilation – Gray-Scale example
Erosion – Gray-Scale
Gray-scale erosion is defined as:
The condition that (s+x),(t+y) have to be in the
domain of f, and x,y have to be in the domain of
b, is completely analogous to the condition in the
binary definition of erosion, where the structuring
element has to be completely combined by the
set being eroded.
The same as in erosion we illustrate with 1-D
function
Erosion– Gray-Scale example 1
Erosion– Gray-Scale (cont)
General effect of performing an erosion in grayscale
images:
1. If all elements of the structuring element are positive, the output
image tends to be darker than the input image.
2. The effect of bright details in the input image that are smaller in
area than the structuring element is reduced, with the degree of
reduction being determined by the grayscale values surrounding
by the bright detail and by shape and amplitude values of the
structuring element itself.
Similar to binary image grayscale erosion and dilation
are duals with respect to function complementation and
reflection.
Dilation & Erosion– Gray-Scale
“flat-top” structuring element in the shape of a parallelepiped of unit
height and size 5x5 pixels
87
Opening And Closing Similar to the binary algorithms
Opening –
Closing –
In the opening of a gray-scale image, we
remove small light details, while relatively
undisturbed overall gray levels and larger bright
features
In the closing of a gray-scale image, we remove
small dark details, while relatively undisturbed
overall gray levels and larger dark features
Opening And Closing
Opening a G-S picture is describable as
pushing object B under the scan-line graph,
while traversing the graph according the
curvature of B
Opening And Closing
Closing a G-S picture is describable as pushing object B
on top of the scan-line graph, while traversing the graph
according the curvature of B
The peaks are usually remains in their original form
Opening And Closing
Applications of G-S Morphology
Morphological smoothing Perform opening followed by a closing
The net result of these two operations is to remove or attenuate both bright and dark artifacts or noise.
Morphological gradient Dilation and erosion are use to compute the
morphological gradient of an image, denoted g:
It uses to highlights sharp gray-level transitions in the input image.
Obtained using symmetrical structuring elements tend to depend less on edge directionality.
Applications of G-S Morphology
Morphological smoothing
Morphological gradient
Applications of G-S Morphology
Top-hat transformation Denoted h, is defined as:
Cylindrical or parallelepiped structuring element functionwith a flat top.
Useful for enhancing detail in the presence of shading.
Textural segmentation The objective is to find the boundary between different
image regions based on their textural content.
Close the input image by using successively larger
structuring elements.
Then, single opening is preformed ,and finally a simple threshold that yields the boundary between the textural regions.
Applications of G-S Morphology
Top-hat transformation
Textural segmentation
Applications of G-S Morphology
Granulometry Granulometry is a field that deals principally with
determining the size distribution of particles in an image.
Because the particles are lighter than the background, we can use a morphological approach to determine size distribution. To construct at the end a histogramof it.
Based on the idea that opening operations of particular size have the most effect on regions of the input image that contain particles of similar size.
This type of processing is useful for describing regions with a predominant particle-like character.
Applications of G-S Morphology
Granulometry
Matlab examples
98
%%dilation
originalBW = imread('text.png');
se = strel('line',11,90);
dilatedBW = imdilate(originalBW,se);
figure, imshow(originalBW), figure,
imshow(dilatedBW)
originalI = imread('cameraman.tif');
se = strel('ball',5,5);
dilatedI = imdilate(originalI,se);
figure, imshow(originalI), figure, imshow(dilatedI)
se1 = strel('line',3,0);
se2 = strel('line',3,90);
composition = imdilate(1,[se1 se2],'full');
99
%%erosion
originalBW = imread('text.png');
se = strel('line',11,90);
erodedBW = imerode(originalBW,se);
figure, imshow(originalBW)
figure, imshow(erodedBW)
originalI = imread('cameraman.tif');
se = strel('ball',5,5);
erodedI = imerode(originalI,se);
figure, imshow(originalI), figure, imshow(erodedI)
100
%%closing
originalBW = imread('circles.png');
figure, imshow(originalBW);
se = strel('disk',10);
closeBW = imclose(originalBW,se);
figure, imshow(closeBW);
%%opening
original = imread('snowflakes.png');
se = strel('disk',5);
afterOpening = imopen(original,se);
figure, imshow(original), figure, imshow(afterOpening)
%%HMT
bw=[0 0 0 0 0 0;0 0 1 1 0 0;0 1 1 1 1 0
0 1 1 1 1 0;0 0 1 1 0 0;0 0 1 0 0 0];
interval = [0 -1 -1;1 1 -1;0 1 0];
bw2 = bwhitmiss(bw,interval)
Top Related