Mathematical Morphology¶


This numerical tour explores mathematical morphology of binary images.

In [2]:
addpath('toolbox_signal')

[Warning: Function isrow has the same name as a MATLAB builtin. We suggest you
rename the function to avoid a potential name conflict.]
[> In path at 110
In pymat_eval at 38
In matlabserver at 27]
[Warning: Function isrow has the same name as a MATLAB builtin. We suggest you
rename the function to avoid a potential name conflict.]
[> In path at 110
In pymat_eval at 38
In matlabserver at 27]


Binary Images and Structuring Element¶

Here we process binary images using local operator defined using a structuring element, which is here chosen to be a discrete disk of varying radius.

In [3]:
n = 256;


Display.

In [4]:
clf;
imageplot(M);


Make it binary.

In [5]:
M = double(M>.45);


Display.

In [6]:
clf;
imageplot(M);


Round structuring element.

In [7]:
wmax = 7;
[Y,X] = meshgrid(-wmax:wmax, -wmax:wmax);
normalize = @(x)x/sum(x(:));
strel = @(w)normalize( double( X.^2+Y.^2<=w^2 ) );


Exercise 1

Display structuring elements of increasing sizes.

In [8]:
exo1()

In [9]:
%% Insert your code here.


Dillation¶

A dilation corresponds to take the maximum value of the image aroung each pixel, in a region equal to the structuring element.

It can be implemented using a convolution with the structuring element followed by a thresholding.

In [10]:
dillation[email protected](x,w)double(perform_convolution(x,strel(w))>0);
Md = dillation(M,2);


Display.

In [11]:
clf;
imageplot(Md);


Exercise 2

Test with structing elements of increasing size.

In [12]:
exo2()

In [13]:
%% Insert your code here.


Errosion¶

An errosion corresponds to take the maximum value of the image aroung each pixel, in a region equal to the structuring element.

It can be implemented using a convolution with the structuring element followed by a thresholding.

In [14]:
errosion[email protected](x,w)double( perform_convolution(x,strel(w))>=.999 );
Me = errosion(M,2);


Display.

In [15]:
clf;
imageplot(Me);


Exercise 3

Test with structing elements of increasing size.

In [16]:
exo3()

In [17]:
%% Insert your code here.


Opening¶

An opening smooth the boundary of object (and remove small object) by performing an errosion and then a dillation.

Define a shortcut.

In [18]:
opening = @(x,w)dillation(errosion(x,w),w);


Perform the opening, here using a very small disk.

In [19]:
w = 1;
Mo = opening(M,w);


Display.

In [20]:
clf;
imageplot(Mo);


Exercise 4

Test with structing elements of increasing size.

In [21]:
exo4()

In [22]:
%% Insert your code here.