Mathematical Morphology

This numerical tour explores mathematical morphology of binary images.

Contents

Installing toolboxes and setting up the path.

You need to download the following files: signal toolbox and general toolbox.

You need to unzip these toolboxes in your working directory, so that you have toolbox_signal and toolbox_general in your directory.

For Scilab user: you must replace the Matlab comment '%' by its Scilab counterpart '//'.

Recommandation: You should create a text file named for instance numericaltour.sce (in Scilab) or numericaltour.m (in Matlab) to write all the Scilab/Matlab command you want to execute. Then, simply run exec('numericaltour.sce'); (in Scilab) or numericaltour; (in Matlab) to run the commands.

Execute this line only if you are using Matlab.

getd = @(p)path(p,path); % scilab users must *not* execute this

Then you can add the toolboxes to the path.

getd('toolbox_signal/');
getd('toolbox_general/');

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.

Load an image

n = 256;
M = rescale( load_image('cortex',n) );

Display.

clf;
imageplot(M);

Make it binary.

M = double(M>.45);

Display.

clf;
imageplot(M);

Round structuring element.

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

Exercice 1: (the solution is exo1.m) Display structuring elements of increasing sizes.

exo1;

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.

dillation=@(x,w)double(perform_convolution(x,strel(w))>0);
Md = dillation(M,2);

Display.

clf;
imageplot(Md);

Exercice 2: (the solution is exo2.m) Test with structing elements of increasing size.

exo2;

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.

errosion=@(x,w)double( perform_convolution(x,strel(w))>=.999 );
Me = errosion(M,2);

Display.

clf;
imageplot(Me);

Exercice 3: (the solution is exo3.m) Test with structing elements of increasing size.

exo3;

Opening

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

Define a shortcut.

opening = @(x,w)dillation(errosion(x,w),w);

Perform the opening, here using a very small disk.

w = 1;
Mo = opening(M,w);

Display.

clf;
imageplot(Mo);

Exercice 4: (the solution is exo4.m) Test with structing elements of increasing size.

exo4;