09 Morph

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 73

What are Morphological Operations?

Morphological operations come from the word “morphing”


in Biology which means “changing a shape”.

Morphing

Image morphological operations are used to manipulate


object shapes such as thinning, thickening, and filling.

Binary morphological operations are derived from


set operations.
Basic Set Operations
Concept of a set in binary image morphology:
Each set may represent one object. Each pixel (x,y) has
its status: belong to a set or not belong to a set.
Translation and Reflection Operations
Translation Reflection
( A)z = c c = a + z, for a ∈ A Bˆ = w w = −b, for b ∈ B

B
A

z = (z1,z2)

(A)z B̂
Logical Operations*

*For binary images only


Logical Operations*
Dilation Operations

A ⊕ B = z Bˆ z ∩ A ≠ φ

This equation is based on obtaining the reflection of B about its


original and shifting this reflection by z. The dilation of A by B the
is the set of all displacement, z, such B̂ and A overlap by at least
one element.

A ⊕ B = z [ Bˆ z ∩ A] ⊆ A

Set B is commonly referred to as the structuring element.In


Dilation Operations
A ⊕ B = z [ Bˆ z ∩ A] ⊆ A
Matlab à Dilation: The value of the output pixel is the maximum value of all
the pixels in the input pixel's neighborhood. In a binary image, if any of the
pixels is set to the value 1, the output pixel is set to 1.
Dilation Operations

A ⊕ B = z Bˆ z ∩ A ≠ φ

φ = Empty set
Dilate means “extend”

A = Object to be dilated
B = Structuring element
Example: Application of Dilation

“Repair” broken characters


Example: Application of Dilation

>> B=[0 1 0; 1 1 1; 0 1 0]
B= Remember! Dilation is an
0 1 0 operation that “grows” or
1 1 1
0 1 0 “thickens” objects in a binary
>> A=imread('fig0905.tif'); image. The specific manner and
>> A2=imdilate(A,B); extent of this thickening is
>> imshow(A);
>> figure;imshow(A2); controlled by a shape refer to as
a structuring element
Example: Application of Dilation
Remember! Dilation is an
operation that “grows” or
“thickens” objects in a binary
image. The specific manner and
extent of this thickening is
controlled by a shape refer to as
a structuring element.
Erosion Operation

A B = z (B )z ⊆ A
The Erosion of A by B is the set of all points z such that B,
translated by z is contained in A.

Erosion means “trim”

A B

A = Object to be eroded
B = Structuring element
Erosion Operation

MatlabàErosion: The
value of the output pixel
is the minimum value of
all the pixels in the input
pixel's neighborhood. In a
binary image, if any of
the pixels is set to 0, the
output pixel is set to 0.
Example: Application of Dilation and Erosion

Remove small objects such as noise

Remember! Erosion “shrinks” or “thins”


objects in binary image.
Duality Between Dilation and Erosion

( A B ) c = Ac ⊕ Bˆ

where c = complement
Proof:

( A B ) = z (B )z ⊆ A
c c

= z (B )z ∩ A = φ
c c

= z (B )z ∩ Ac ≠ φ
= A ⊕ Bˆ
c
Opening Operation
A o B = ( A B) ⊕ B
or
A o B = ∪ (B )z (B )z ⊆ A
= Combination of all parts of A that can completely contain B

Opening eliminates narrow and small details and corners.


Example of Opening

(Images from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Closing Operation
A • B = (A ⊕ B) B

Closing fills narrow gaps and notches


Example of Closing

(Images from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Duality Between Opening and Closing

(A • B) c
= Ac o Bˆ

Properties Opening
1. A o B ⊆ A
2. If C ⊂ D then C o B ⊂ D o B
3. ( A o B ) o B = A o B
Properties Closing
1. A ⊆ A • B
2. If C ⊂ D then C • B ⊂ D • B
3. ( A • B ) • B = A • B
Idem potent property: can’t change any more
Example: Application of Morphological Operations
Finger print enhancement
f=imread('fig911.tif');
se=strel('square',3)
fo=imopen(f,se);
imshow(fo);
foc=imclose(fo,se);
figure;imshow(foc);

(Images from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Hit--or
Hit or--Miss Transformation
A *B= A X ∩ Ac (W − X )

where X = shape to be detected


W = window that can contain X
Hit--or
Hit or--Miss Transformation (cont.)
A *B= A X ∩ Ac (W − X )
Hit--or
Hit or--Miss Transformation (cont.)
A *B= A X ∩ Ac (W − X )
However, if we consider B is a structuring pair, B = (B1, B2)
where B1=X and B2 =(W-X). We can rewrite as:
A *B= A B1 ∩ A c
B2
Complement of the
Original Image original image Ac
Output Image

Erosion of A by B1 Erosion of Ac by B2
Hit--or
Hit or--Miss Transformation (cont.)
Matlab command
C=bwhitmis(A,B1,B2);

Example:
>>f=imread(‘Fig0913.tif’);

>>B1=strel([0 0 0;0 1 1; 0 1 0]);


>>B2=strel([1 1 1;1 0 0; 1 0 0]);
>>g= bwhitmiss(f,B1,B2);
>>imshow(g);
Boundary Extraction

The boundary of set A, β(A) = A − A B


denoted byβ ( A) , can be
obtained by first eroding A
by B (suitable structuring
element) and then
performing the set difference
between A and its erosion.

Original Boundary
image
Boundary Extraction
β(A) = A − A B
A=imread('fig914.jpg');
B=strel('square',3)

AeB=imerode(A,B);
Bon=A-AeB;
imshow(Bon);

Original Boundary
image
Region Filling
X k = ( X k −1 ⊕ B ) ∩ Ac

where X0 = seed pixel p

Original Results of region filling


image
Extraction of Connected Components

X k = ( X k −1 ⊕ B ) ∩ A where X0 = seed pixel p


Example: Extraction of Connected Components

X-ray image
of bones

Thresholded
image

Connected
components
(Images from Rafael C.
Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Convex Hull
Convex hull has no concave part.
Convex hull

4
Algorithm: C ( A) = D i where D i = X conv
i

i =1

X ki = X k −1 * B i ∪ A, i = 1,2,3,4 convergence
Example: Convex Hull

X ki = X k −1 * B i ∪ A,
i = 1,2,3,4
Thinning

A ⊗ B = A − ( A * B)
= A ∩ ( A * B )c

A ⊗ {B} = ((...(( A ⊗ B1 ) ⊗ B 2 )...) ⊗ B n )


A ⊗ {B} = ((...(( A ⊗ B1 ) ⊗ B 2 )...) ⊗ B n )
Example: Thinning

Make an object
thinner.
Thickening
A B = A ∪ ( A * B)
A {B} = ((...(( A 1
B) 2
B )...) n
B )

However, we can do as
follow:
1. C=Ac
2. Thin C
3. Form Cc

Make an object thicker


Skeletons
Skeleton, S(A), of a set A is:

(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 disk (not necessarily
centered at z) containing (D)z, and
included in A. The disk (D)z, is
called a maximum disk.

(b) The disk (D), touches the


boundary of A at two or more
different places.

Dot lines are


skeletons of this
structure
Skeletons (cont.)
K
S ( A) = Sk ( A)
k =0

with Sk ( A) = ( A kB) − ( A kB) o B

where ( A kB) = (...( A B ) B ) ...) B


k times

and K = max k ( A kB ) ≠ φ
Skeletons
Pruning

X 1 = A ⊗ {B} = thinning
8
X2 = k
( X 1 * B ) = finding end points
k =1

X 3 = ( X 2 ⊕ H ) ∩ A = dilation at end points

X 4 = X 1 ∪ X 3 = Pruned result
Example: Pruning

Original
image

After
Thinning End
3 times points

Dilation
of end Pruned
points result
Summary of Binary Morphological Operations

(Tables from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Summary of Binary Morphological Operations (cont.)

(Tables from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Summary of Binary Morphological Operations (cont.)

(Tables from Rafael C.


Gonzalez and Richard E.
Wood, Digital Image
Processing, 2nd Edition.
Summary of Binary Morphological Operations (cont.)
Basic Types of Structuring Elements

x = don’t care
Gray--Scale Dilation
Gray
1-D Case f ⊕ b = max{f ( s − x ) + b( x ) | ( s − x ) ∈ D f and x ∈ Db }
2-D Case
f ⊕ b = max{f ( s − x, t − y ) + b( x, y ) | ( s − x ), (t − y ) ∈ D f ; ( x, y ) ∈ Db }
Gray--Scale Dilation (cont.)
Gray
Original image Reflection
Subimage of B
+

Max
Moving
window

Structuring
element B

Note: B can be any shape and


subimage must have
the same shape as
reflection of B. Output image
Gray--Scale Erosion
Gray
1-D Case f − b = min{f ( s + x ) − b( x ) | ( s + x ) ∈ D f and x ∈ Db }
2-D Case
f − b = min{f ( s + x, t + y ) − b( x, y ) | ( s + x ), (t + y ) ∈ D f ; ( x, y ) ∈ Db }
Gray--Scale Erosion (cont.)
Gray
Original image
Subimage B
-

Min
Moving
window
Structuring
element B

Note: B can be any shape and


subimage must have
the same shape as B.
Output image
Example: Gray-
Gray-Scale Dilation and Erosion
Original image After dilation

Darker Brighter

After erosion
Gray--Scale Opening
Gray
f o b = ( f − b) ⊕ b

Opening cuts peaks


Gray--Scale Closing
Gray
f • b = ( f ⊕ b) − b

Closing fills valleys


Example: Gray-
Gray-Scale Opening and Closing

Original image After opening After closing

Reduce dark
Reduce white objects
objects
Gray--scale Morphological Smoothing
Gray
Smoothing: Perform opening followed by closing

Original image After smoothing


Gray--scale Morphological Smoothing
Gray
Smoothing: Perform opening followed by closing
Morphological Gradient
g = ( f ⊕ b) − ( f − b)

Original image Morphological Gradient


Morphological Gradient
g = ( f ⊕ b) − ( f − b)
Top--Hat Transformation
Top

h = f − ( f o b)

Original image Results of top-hat transform


Top--Hat Transformation
Top

h = f − ( f o b)
Example: Texture Segmentation Application

Small
blob

Original image Segmented result


Large blob
Algorithm:
1. Perform closing on the image by using successively larger
structuring elements until small blobs are vanished.
2. Perform opening to join large blobs together
3. Perform intensity thresholding
Example: Granulometry
Objective: to count the number of particles of each size
Method:
1. Perform opening using structuring elements of increasing size
2. Compute the difference between the original image and the result
after each opening operation
3. The differenced image obtained in Step 2 are normalized and used
to construct the size-distribution graph.

Size distribution
Original image graph
Example: Granulometry
Example: Granulometry
Matlab:: morphological processing
Matlab
Matlab:: morphological processing
Matlab
Matlab:: Create Structural Element
Matlab
SE=strel(‘shape’, parameter)

>>se=strel('diamond',3)

0 0 0 1 0 0 0
0 0 1 1 1 0 0
0 1 1 1 1 1 0
1 1 1 1 1 1 1
0 1 1 1 1 1 0
0 0 1 1 1 0 0
0 0 0 1 0 0 0

Size distribution
graph
Matlab:: morphological processing
Matlab
bwmorph
Morphological operations on binary images
Syntax
BW2 = bwmorph(BW,operation)
BW2 = bwmorph(BW,operation,n)
Matlab:: bwmorph
Matlab
Matlab:: bwmorph
Matlab

Size distribution
Original image graph
Matlab:Label connected components in binary image
bwlabel
Syntax
L = bwlabel(BW,n)
[L,num] = bwlabel(BW,n)
Description
L = bwlabel(BW,n) returns a matrix L, of the same size as BW, containing labels for
the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-
connected objects and 8 specifies 8-connected objects; if the argument is omitted, it
defaults to 8.

The elements of L are integer values greater than or equal to 0. The pixels labeled 0
are the background. The pixels labeled 1 make up one object, the pixels labeled 2
make up a second object, and so on.

[L,num] = bwlabel(BW,n) returns in num the number of connected objects found in


BW.
Matlab:Label connected components in binary image
Examples
Label components using 4-connected objects. Notice objects 2 and 3; with 8-connected
labeling, bwlabel would consider these a single object rather than two separate objects.
BW = [1 1 1 0 0 0 0 0
1 1 1 0 1 1 0 0
1 1 1 0 1 1 0 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 0 0 0 0];
L = bwlabel(BW,4)
L=
1 1 1 0 0 0 0 0
1 1 1 0 2 2 0 0
1 1 1 0 2 2 0 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 3 3 0
1 1 1 0 0 0 0 0
[r,c] = find(L==2);
rc = [r c]
rc =
2 5
3 5
2 6
3 6
Matlab:Morphological process usages

Examples
>> f=imread('rice.png');
>> imshow(f);
>> figure;imhist(f);
>> figure;imshow(f>140);
>> se=strel('disk',10);
>> fo=imopen(f,se);
>> figure;imshow(fo);
>> f2=imsubtract(f,fo);
>> figure;imshow(f2);
>> figure;imhist(f);
>> figure;imshow(f2>50);

You might also like