You are on page 1of 14

Gray-Scale Morphology

Gray-Scale Morphology
f ( x, y ) : gray-scale image
b( x, y ): structuring element

2 09/07/2023
Gray-Scale Morphology: Erosion and Dilation
by Flat Structuring
 f  b  ( x , y )  (ms , t in
) b
 f ( x  s , y  t )

f  b ( x , y )  m a x  f ( x  s , y  t )
( s , t ) b

%Dilation
f=f1(:,:,1);
[x,y]=size(f);
p=zeros(x,y);p2=zeros(x,y);p12=zeros(x,y);p13=zeros(x,y);
w=[1 1 1; 1 1 1; 1 1 1];
for s=2:x-2
for t=2:y-2
w1=[f(s-1,t-1)*w(1) f(s-1,t)*w(2) f(s-1,t+1)*w(3) f(s,t-1)*w(4) f(s,t)*w(5)
f(s,t+1)*w(6) f(s+1,t-1)*w(7) f(s+1,t)*w(8) f(s+1,t+1)*w(9)];
p(s,t)=max(w1);
end
3 end 09/07/2023
4 09/07/2023
Gray-Scale Morphology: Erosion and Dilation
by Nonflat Structuring
 f  bN  ( x, y )  (min
s ,t )b
 f ( x  s, y  t )  bN ( s, t )

 f  bN  ( x, y)  max
( s ,t )b
 f ( x  s, y  t )  bN ( s, t )

5 09/07/2023
https://in.mathworks.com/matlabcentral/fileexchange/52363-morphological-operations-
on-a-grayscale-image

SE = strel(nhood)
SE = strel("rectangle",[m n])
SE = strel("diamond",r)
SE = strel("disk",r) SE = strel("square",w)
SE = strel("disk",r,n) SE = strel("cube",w)
SE = strel("octagon",r) SE = strel("cuboid",[m n p])
SE = strel("line",len,deg) SE = strel("sphere",r)
originalBW = imread('text.png'); original = imread('snowflakes.png');
se = strel('line',11,90); figure,imshow(original);
erodedBW = imerode(originalBW,se); se = strel('disk',5);
figure, afterOpening = imopen(original,se);
figure,
imshow(originalBW)
imshow(afterOpening,[]);
figure,
title('After Opening')
imshow(erodedBW)
title('After Erosion') originalBW = imread('circles.png');
dilatedBW = imdilate(originalBW,se); figure,imshow(originalBW);
figure, se = strel('disk',10);
imshow(dilatedBW) closeBW = imclose(originalBW,se);
figure, imshow(closeBW)
title('After Dilation')
6 title('After Closing') 09/07/2023
Morphological Smoothing
 Opening suppresses bright details smaller than the
specified SE, and closing suppresses dark details.

 Opening and closing are used often in combination as


morphological filters for image smoothing and noise
removal.

Opening and Closing

f  b   f  b  b
f  b   f  b  b
7 09/07/2023
Morphological Smoothing

8 09/07/2023
Morphological Gradient
 Dilation and erosion can be used in combination with
image subtraction to obtain the morphological gradient of
an image, denoted by g,

g  ( f  b)  ( f  b)
 The edges are enhanced and the contribution of the
homogeneous areas are suppressed, thus producing a
“derivative-like” (gradient) effect.

9 09/07/2023
Morphological Gradient

10 09/07/2023
Top-hat and Bottom-hat Transformations
 The top-hat transformation of a grayscale image f is
defined as f minus its opening:

That ( f )  f  ( f  b)
 The bottom-hat transformation of a grayscale image f is
defined as its closing minus f:

Bhat ( f )  ( f  b)  f

11 09/07/2023
Example of Using Top-hat Transformation in
Segmentation

12 09/07/2023
Granulometry
 Granulometry deals with determining the size of
distribution of particles in an image

 Opening operations of a particular size should have the


most effect on regions of the input image that contain
particles of similar size

 For each opening, the sum (surface area) of the pixel


values in the opening is computed

13 09/07/2023
Example

14 09/07/2023

You might also like