Important: Please read the installation page for details about how to install the toolboxes. $\newcommand{\dotp}[2]{\langle #1, #2 \rangle}$ $\newcommand{\enscond}[2]{\lbrace #1, #2 \rbrace}$ $\newcommand{\pd}[2]{ \frac{ \partial #1}{\partial #2} }$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\umax}[1]{\underset{#1}{\max}\;}$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\uargmin}[1]{\underset{#1}{argmin}\;}$ $\newcommand{\norm}[1]{\|#1\|}$ $\newcommand{\abs}[1]{\left|#1\right|}$ $\newcommand{\choice}[1]{ \left\{ \begin{array}{l} #1 \end{array} \right. }$ $\newcommand{\pa}[1]{\left(#1\right)}$ $\newcommand{\diag}[1]{{diag}\left( #1 \right)}$ $\newcommand{\qandq}{\quad\text{and}\quad}$ $\newcommand{\qwhereq}{\quad\text{where}\quad}$ $\newcommand{\qifq}{ \quad \text{if} \quad }$ $\newcommand{\qarrq}{ \quad \Longrightarrow \quad }$ $\newcommand{\ZZ}{\mathbb{Z}}$ $\newcommand{\CC}{\mathbb{C}}$ $\newcommand{\RR}{\mathbb{R}}$ $\newcommand{\EE}{\mathbb{E}}$ $\newcommand{\Zz}{\mathcal{Z}}$ $\newcommand{\Ww}{\mathcal{W}}$ $\newcommand{\Vv}{\mathcal{V}}$ $\newcommand{\Nn}{\mathcal{N}}$ $\newcommand{\NN}{\mathcal{N}}$ $\newcommand{\Hh}{\mathcal{H}}$ $\newcommand{\Bb}{\mathcal{B}}$ $\newcommand{\Ee}{\mathcal{E}}$ $\newcommand{\Cc}{\mathcal{C}}$ $\newcommand{\Gg}{\mathcal{G}}$ $\newcommand{\Ss}{\mathcal{S}}$ $\newcommand{\Pp}{\mathcal{P}}$ $\newcommand{\Ff}{\mathcal{F}}$ $\newcommand{\Xx}{\mathcal{X}}$ $\newcommand{\Mm}{\mathcal{M}}$ $\newcommand{\Ii}{\mathcal{I}}$ $\newcommand{\Dd}{\mathcal{D}}$ $\newcommand{\Ll}{\mathcal{L}}$ $\newcommand{\Tt}{\mathcal{T}}$ $\newcommand{\si}{\sigma}$ $\newcommand{\al}{\alpha}$ $\newcommand{\la}{\lambda}$ $\newcommand{\ga}{\gamma}$ $\newcommand{\Ga}{\Gamma}$ $\newcommand{\La}{\Lambda}$ $\newcommand{\si}{\sigma}$ $\newcommand{\Si}{\Sigma}$ $\newcommand{\be}{\beta}$ $\newcommand{\de}{\delta}$ $\newcommand{\De}{\Delta}$ $\newcommand{\phi}{\varphi}$ $\newcommand{\th}{\theta}$ $\newcommand{\om}{\omega}$ $\newcommand{\Om}{\Omega}$
This numerical tour explores mathematical morphology of binary images.
addpath('toolbox_signal')
addpath('toolbox_general')
addpath('solutions/denoisingadv_5_mathmorph')
[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 addpath at 87 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 addpath at 87 In pymat_eval at 38 In matlabserver at 27]
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 ) );
Exercise 1
Display structuring elements of increasing sizes.
exo1()
%% Insert your code here.
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);
Exercise 2
Test with structing elements of increasing size.
exo2()
%% Insert your code here.
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);
Exercise 3
Test with structing elements of increasing size.
exo3()
%% Insert your code here.
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);
Exercise 4
Test with structing elements of increasing size.
exo4()
%% Insert your code here.