0% found this document useful (0 votes)
52 views79 pages

Chapter 9 Morphological Image Processing1

This document provides an overview of morphological image processing. It defines morphology as dealing with the form and structure of objects, and mathematical morphology as using set theory and operations to extract image components and describe shapes. The document outlines concepts like dilation, erosion, opening, closing and hit-or-miss transforms. It also provides examples of using structuring elements to perform morphological operations on binary images.

Uploaded by

Hsu Let Yee Hnin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views79 pages

Chapter 9 Morphological Image Processing1

This document provides an overview of morphological image processing. It defines morphology as dealing with the form and structure of objects, and mathematical morphology as using set theory and operations to extract image components and describe shapes. The document outlines concepts like dilation, erosion, opening, closing and hit-or-miss transforms. It also provides examples of using structuring elements to perform morphological operations on binary images.

Uploaded by

Hsu Let Yee Hnin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 79

Chapter 9

Morphological Image Processing

Faculty of Computer Science


University of Computer Studies, Mandalay

1 UCSM
Contents
 Basic Concepts in Set Theory
 Logic Operations Involving Binary Pixels and Images
 Dilation and erosion
 Opening and closing
 The Hit-or-Miss Transformation
 Some basic morphological algorithms

2 UCSM
Morphological Image Processing
“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 – Z2, where each element (x,y) is a coordinate of a
black (or white) pixel in the image.

3 UCSM
Basic Concepts in Set Theory
Subset

Union

Intersection

disjoint / mutually exclusive


Complement
Difference
Reflection
Translation

4 UCSM
Logic Operations Involving Binary Pixels
and Images
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.

5 UCSM
6 UCSM
Logical expressions in Matlab for set
operations
Set Operation Matlab expression Name
for Binary images
A B A& B AND
A B A| B OR
Ac ~A NOT
A-B A& ~B DIFFERENCE

7 UCSM
Dilation
Dilation is used for expanding an element A by using
structuring element B
 Dilation of A by B and is defined by the following equation:

 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 equation of (9.2-1) can be rewritten as:

 One of the simplest applications of dilation is for bridging


gaps.

8 UCSM
Dilation – Example 1

9 UCSM
Dilation – Example 2

10 UCSM
Dilation – A More interesting Example

11 UCSM
Dilation –Example
A=imread(‘broken_text.tif’);
B=[0 1 0;1 1 1;0 1 0];
A2=imdilate(A, B);
imshow(A2)

12 UCSM
The strel function
IPT function strel constructs structuring elements with a
variety of shapes and sizes.
 se=strel(shape,parameters)
shape –string specifying the desired shape
parameters– list of parameters
se=strel(‘diamond’,5) //diamond-shaped structuring element
return diamond-shaped structuring element that extends ±5
pixels along the horizontal and vertical axes
Some shapes that strel create are:
se=strel(‘disk’,R)
se=strel(‘line’,LEN,DEG)
se=strel(‘square’,W)

13 UCSM
Erosion
Erosion is used for shrinking of element A by using
element B
Erosion for Sets A and B in Z2, is defined by the following
equation:

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.
One of the simplest uses of erosion is for eliminating
irrelevant details (in terms of size) from a binary image.

14 UCSM
Erosion – Example 1

15 UCSM
Erosion – Example 2

16 UCSM
Duality between dilation and erosion
Dilation and erosion are duals of each other with respect to set
complementation and reflection. That is,

Proof;
Erosion- (AB)c {z | (B)z  A}c
If set (B)z is contained in set A, then (B)z ∩ Ac =Ø in which case
the preceding equation becomes
( AB) c  {z | (B) z  Ac  }c

But the complement of the set of z’s that satisfy (B)z∩ Ac = Ø is


the set of z’s such that (B)z ∩ Ac ≠ Ø.
( AB)c  {z | ( B) z  Ac  }
^
 Ac  B
17 UCSM
Erosion and Dilation

18 UCSM
Example
A=imread(‘wire.tif’);
se=strel(‘disk’,10);
A2=imerode(A,se);
imshow(A2)

19 UCSM
Image Dilation without using 'imdilate' function
Steps to be performed
1.Consider a matrix A=

2.And structuring element B=[1 0 1]


3.Initialize a matrix of size A with zeros. Let D=
4.Pad the matrix A with zeros on both sides.
A=

5.Place the structuring element B on the matrix A and perform


logical AND operation.
A=

20 UCSM
Con’t
5.If the values are zero, then, update the matrix D with zero on the
position (1,1)
6.Now slide the structuring element to the next position and
perform logical AND operation.

7. If the values after the logical AND operation is not zero, and
then update the matrix D with one.
D=

21 UCSM
Cont’d
8.Repeat this process until all the elements in the matrix A
are visited.
9.The final result after dilation using the structuring
element B is

22 UCSM
Matlab code (Example 1)
A=[1 0 0 0 1; 1 0 1 0 0; 1 1 1 0 0;0 0 1 1 1];
%Structuring element
B=[1 0 0; 0 1 0; 0 0 1];
%Pad zeros on all the sides
C=padarray(A,[1 1]);
%Intialize a matrix of matrix size A with zeros
D=false(size(A));
for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Perform logical AND operation
        D(i,j)=sum(sum(B&C(i:i+2,j:j+2)));
    end
end
display(D);
23 UCSM
Explanation

24 UCSM
Matlab code (Example 2)
A=imread('text.png');
A=im2bw(A);
%Structuring element
B2=getnhood(strel('line',7,90));
m=floor(size(B2,1)/2);
n=floor(size(B2,2)/2);
%Pad array on all the sides
C=padarray(A,[m n]);
D=false(size(A));
for i=1:size(C,1)-(2*m)
    for j=1:size(C,2)-(2*n)
        Temp=C(i:i+(2*m),j:j+(2*n));
        D(i,j)=max(max(Temp&B2));
    end
end
figure,imshow(D);
25 UCSM
Image Erosion without using MATLAB
function 'imerode'
Steps to be performed
1.Consider a matrix A=

2.And structuring element B=[1 1 0]


3.Initialize a matrix of size A with zeros. Let D=
4.Pad the matrix A with zeros on both sides.

A=

5.Place the structuring element B on the matrix A and check whether the ones in
the structuring element overlaps only the ones in the matrix A.

A= B B=[1 1 0]

26
UCSM
Cont’d
6.If the condition is true, then update matrix D with one. And slide the widow to
next position.
D=

7.The ones in the structuring element do not overlap with the ones in the matrix A,
update the matrix D with 0.

8.Repeat the procedure for all the element in the matrix A.


9.The result after erosion D=

27 UCSM
Cont’d
A=[1 0 1 1 1; 1 0 1 0 0; 1 1 1 0 0;0 0 1 1 1];
B=[1 1 0]; %Structuring element
C=padarray(A,[0 1],1); %Pad array with ones on both sides
D=false(size(A)); %Intialize the matrix D of size A with zeros
for i=1:size(C,1)
    for j=1:size(C,2)-2
        In=C(i,j:j+2);
        %Find the position of ones in the structuring element
        In1=find(B==1);
        %Check whether the elements in the window have the value one in the
        %same positions of the structuring element
        if(In(In1)==1)
        D(i,j)=1;
        end
    end
end
28
display(D); UCSM
Erosion

Original Image After Erosion

29 UCSM
Opening And Closing
Opening – smoothes contours , eliminates protrusions

Closing – smoothes sections of contours, fuses narrow


breaks and long thin gulfs, eliminates small holes and fills
gaps in contours

These operations are dual to each other

These operations are can be applied few times, but has


effect only once

30 UCSM
Opening And Closing
Opening –
 eliminates protrusions
 breaks necks
 smoothes contour
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

C=imopen (A, B)

31 UCSM
Opening

A
B
)
(
A
BB
A
B

{(
B)
|
z(
B
)
zA}
32
33
UCSM
Opening And Closing
Closing –
 smooth contour
 fuse narrow breaks and long thin gulfs
 eliminate small holes
 fill gaps in the contour
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

 C=imclose (A, B)

34 UCSM
Closing


A
B
(
A
B
)B

35
36 UCSM
Use of opening and closing for morphological filtering

37 UCSM
Example
f=imread(‘figerprint.tif’);
se= strel(‘square’,3);
fo=imopen(f,se);
imshow (fo)

foc= imclose((fo,se);
imshow(foc)

38 UCSM
Useful: open and close

39
The Hit-or-Miss Transformation
 A basic morphological tool for shape detection and can be
used to look for particular patterns of foreground and
background pixels in an image.
 Let the origin of each shape be located at its center of gravity.
 If we want to find the location of a shape , say – X , at (larger)
image, say – A :
Let X be enclosed by a small window, say – W.
The local background of X with respect to W is defined as
the set difference (W - X).
Apply erosion operator of A by X, will get us the set of
locations of the origin of X, such that X is completely
contained in A.
It may be also view geometrically as the set of all locations
40 of the origin of X at which X found a match (hit) in A. UCSM
The Hit-or-Miss Transformation
 Apply erosion operator on the complement of A by the local
background set (W – X).
 Notice, that the set of locations for which X exactly fits inside
A is the intersection of these two last operators above.
This intersection is precisely the location sought.
 Formally:
If B denotes the set composed of X and it’s background –
B = (B1,B2) ; B1 = X , B2 = (W-X).
The match (or set of matches) of B in A, denoted is:

41
UCSM
Hit-or-Miss exp:

42
UCSM
Basic Morphological Algorithms
1 – Boundary Extraction
2 – Region Filling
3 – Extraction of Connected Components
4 – Convex Hull
5 – Thinning
6 – Thickening
7 – Skeletons

43 UCSM
Boundary Extraction
First, erode A by B, then make set difference between A
and the erosion
The thickness of the contour depends on the size of
constructing object – B

44
UCSM
Boundary Extraction

45 UCSM
Region Filling
 This algorithm is based on a set of dilations, complementation
and intersections
 Begin p, is the point inside the boundary, to fill the entire region
with 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 A and X(k), is a set contains
the filled set and the boundary

46
UCSM
Application: region filling
The first filled
region Fill all regions
Original image
Extraction of Connected Components

This algorithm extracts a component by selecting a point


on a binary object A
Works similar to region filling, but this time we use in the
conjunction the object A, instead of it’s complement

48 UCSM
This shows automated
inspection of chicken-
breast, that contains
bone fragment

The original image is


thresholded

We can get by using


this algorithm the
number of pixels in
each of the connected
components

Now we could know


if this food contains
big enough bones and
prevent hazards
49 UCSM
Convex Hull
 A is said to be convex if a straight line segment joining any two
points in A lies entirely within A
 The convex hull H of set S is the smallest convex set containing S
 Convex deficiency is the set difference H-S
 Useful for object description
 This algorithm iteratively applying the hit-or-miss transform to A
with the first of B element, unions it with A, and repeated with
second element of B

50 UCSM
Convex hull
(morphological
algorithm) - example

51 UCSM
Convex hull (morphological algorithm) - example

52 UCSM
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:

53 UCSM
Thinning (cont’d)
The process is to thin by one pass with B 1 , 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:

54 UCSM
Thinning example

B8

55 UCSM
(a)Sequence of rotated
structuring elements used for
thinning (b) Set A (c)Result
of thinning with the first
element (d)-(i) Results of
thinning with the next seve
elements (there was no
change between the seventh
and eight elements) (j)Result
of using the first four
elements again (there was no
change between the seventh
and eight elements)(k) Result
after covergence (l)
56 UCSM Conversion to m-
connectivity
Thickening
Thickening is a morphological dual of thinning.
Thickening is used to grow selected regions of foreground
pixels in binary images, somewhat like dilation or closing.
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.

57 UCSM
Thickening (cont’d)
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=A c , thin C and


then 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.

58 UCSM
Thickening example

59 UCSM
Skeleton
The notion of a skeleton S(A) of a set A is intuitively
defined,

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) – this disk is called “maximum disk”.

b) The disk (D)z touches the boundary of A at two or


more different places.

60 UCSM
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:

 S(A) can be obtained as the union of skeleton subsets Sk(A).

61 UCSM
Skeleton
A can be also reconstructed from subsets Sk(A) by
using the equation:

Where denotes k successive dilations of


Sk(A) that is:

62 UCSM
Skeleton
 Maximum disk: largest disk included in A, touching the
boundary of A at two or more different places

63
UCSM
Skeleton

64 UCSM
Skeleton Example

BW1 = imread('circbw.tif');
BW2 = bwmorph(BW1,'skel',Inf);
imshow(BW1)
figure, imshow(BW2)
65 UCSM
Some Matlab Functions
bwmorph
Morphological operations on binary images
Remove interior pixels to leave an outline of the shapes.
BW2 = bwmorph(BW,'remove');
BW3 = bwmorph(BW,'skel',Inf);
imshow(bwmorph(BW, 'thin', Inf));
imshow(bwmorph(BW, 'thicken', Inf));
imshow(bwmorph(BW, 'tophat', Inf));
imfill
Fill image regions and holes
BW2 = imfill(BW,locations)
BW2 = imfill(BW,'holes')
I2 = imfill(I) //fills holes in the grayscale image I.
66 UCSM
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.

67 UCSM
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.

68 UCSM
Dilation – Gray-Scale (cont)
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.

69 UCSM
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 then the output image tends to be brighter
than the input.

2. Dark details either are reduced or eliminated,


depending on how their values and shape relate to
the structuring element used for dilation

70 UCSM
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

71 UCSM
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.
72 UCSM
Dilation & Erosion– Gray-Scale

73 UCSM
Opening And Closing
Similar to the binary algorithms
Opening –
Closing –
In the opening of a gray-scale image, 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

74 UCSM
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

75 UCSM
Some Applications of Gray-Scale Morphology
Morphological smoothing: opening followed by closing

76 UCSM
Some Applications of Gray-Scale Morphology
Morphological gradient: difference between dilation and
erosion

77 UCSM
Some Applications of Gray-Scale Morphology
Top-hat transformation: difference between original
and opening

78
UCSM
Some Applications of Gray-Scale Morphology
 Texture segmentation:
1.Closing with a larger and larger s.e. until the small particles
disappear
2. Opening with a s.e. larger than the gaps between large particles
3. Gradient separation contour

79 UCSM

You might also like