Lecture 9 - Morphological Image Processing
Lecture 9 - Morphological Image Processing
• Erosion
• Dilation
• Opening
• Closing
Morphology
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, boundary
extraction, pruning, thinning, Skeletonization, etc.
What is mathematical morphology?
3
Difference
Translation
Reflection
Fundamental concepts and operations
5
Fundamental concepts and operations
6
Logical equivalents of(e) set theory operations
(f)
Intersection
Figur e 13.1 ~Basic
logical AND
set operations: (a) set A ; (b) translation of A by x =
c
(x 1 , x 2 ); (c) set B ; (d)
reflection of B ; (e) set A and its complement A ; (f) set difference (A − B ).
The equivalent expression using conventional image processing notation would be:
⇢
1 if A (x , y) and B (x , y) are both 1
C (x , y) = (13.6)
0 otherwise
This expression leads quite easily to a single MATLAB statement that perform the
intersection operation using the logical operator AND (&). Similarly, complement can be
obtianed using the unary NOT (~) operator, set union can be implemented using the logical
Similarly:
operator OR (| ) and set difference (A − B ) can be expressed as ( A & ~B) . Figure 13.2
shows representative results for two binary input images. Please note that we have followed
Complement ~ logical NOT
the IPT convention, representing foreground (1-valued) pixels as white pixels against a black
Union ~ logical OR
background.
The structuring element (SE) is the basic neighborhood structure associated with morpho-
logical image operations. It is usually represented as a small matrix, whose shape and size
Fundamental concepts and operations
7
Examples:
square cross
MATLAB functions
strel
getsequence
The structuring element
10
Examples:
Structuring Elements
Structuring elements can be any size and make any shape
However, for simplicity we will use rectangular structuring elements
with their origin at the middle pixel
0 0 1 0 0
1 1 1 0 1 0 0 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 0 0 1 1 1 0
0 0 1 0 0
Structuring Elements, Hits & Fits
Structuring Element
B
Fit: All on pixels in the structuring element cover
on pixels in the image
0 0 1 1 1 1 1 1 0 0 0 0 0 1 0
0 0 1 1 1 1 1 1 1 0 0 0 1 1 1
0 0 1 1 1 1 1 A1 1 1 1 0 0 1 0
0 0 0 0 0 1 1 1 1 1 1 0 Structuring
Element 2
0 0 0 0 0 0 0 0 0 0 0 0
Erosion
• 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:
1 if s fits f
g ( x, y )
0 otherwise
Erosion shrinks objects
Erosion Example
Original Image Processed Image With Eroded Pixels
Structuring Element
Erosion
16
• 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.
Erosion
17
Erosion – geometrical interpretation
Erosion 18
a = [ 0 0 0 0 0 ; 0 1 1 1 0; 1 1 1 0 0; 0 1 1 1 1; 0 0 0 0 0]
se1 = strel('square',3)
b = imerode (a,se1)
1 if s hits f
g ( x, y )
0 otherwise
Dilation enlarges objects
Dilation Example
Original Image Processed Image
Structuring Element
Dilation
21
Dilation – Example
Dilation 25
se1 = strel('square',3)
b = imdilate (a,se1)
Opening: f ○ s = (f s) s
Closing: f s = (f s) s
Compound Operations (Opening & Closing)
28
or:
In MATLAB: imclose
Compound Operations (Example)
30
Compound Operations (Example)
31
Compound Operations (Example)
32
Operations
supported by
bwmorph
Basic Morphological Algorithms
33
Boundary Extraction
Hole Filling
Extraction of Connected Components
Thinning
Thickening
Skeletons
Pruning
Reconstruction
Segmentation of Water in Bottles
b = imread('bottles.jpg');
t=double(multithresh(b,2))/256
bL = im2bw(b,t(1));
bH = im2bw(b,t(2));
L = bL - bH;
se5 = strel('disk',5);
se10 = strel('disk',10);
L1 = imopen(L,se5);
L2 = imclose(L1,se10);
Bottles Liquid White Liquid Black
subplot(2,3,1),imshow(b),title('Bottles'),
subplot(2,3,2), imshow(bL), title('Liquid White'),
subplot(2,3,3), imshow(bH), title('Liquid Black'),
subplot(2,3,4), imshow(L), title('Liquid with noise'),
subplot(2,3,5), imshow(L1), title('Liquid with less noise'), Liquid with noise Liquid with less noise Pure Liquid