# Geodesic Segmentation¶


This tour explores the use of Fast Marching methods for image segmentation.

In [2]:
addpath('toolbox_signal')
addpath('toolbox_general')
addpath('toolbox_graph')
addpath('solutions/fastmarching_8_segmentation')


## Segmentation Using Geodesic Ball¶

It is possible to extract an object by growing a geodesic ball.

First we load an image.

In [3]:
n = 256;
name = 'cortex';
M = rescale( sum(load_image(name,n),3) );


Display.

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


Starting point of the grodesic ball.

In [5]:
pstart = [154;175];


Choose a metric that is minimal for value of the image close to pstart.

In [6]:
W = abs(M-M(pstart(1),pstart(2)));
W = rescale( max(W,0.03), 0.01,1).^2;


Compute the Fast Marching from the center.

In [7]:
clear options;
options.nb_iter_max = Inf;
options.end_points = [];
[D,S,Q] = perform_fast_marching(1./W, pstart, options);


Exercise 1

Display geodesic balls {x \ M(x)<T} for various T.

In [8]:
exo1()

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


## Segmentation Using Voronoi Diagrams¶

It is possible to perform the segmentation by using an edge stopping metric, and Vornoi diagram for several seeds.

Magnitude of the gradient.

In [10]:
mu = 2;
d = sqrt( sum( grad(perform_blurring(M,mu)).^2, 3) );
d = perform_blurring(d,mu);


Edge stopping metric.

In [11]:
W = rescale( min(d,0.15), 0.01,1).^2;


Display the metric.

In [12]:
clf;
imageplot(W);


Starting points.

In [13]:
pstart = [[30;30] [139;86] [158;170] [128;134] [124;122]];


Perform propagation.

In [14]:
options.nb_iter_max = Inf;
options.end_points = [];
[D,S,Q] = perform_fast_marching(1./W, pstart, options);


Display Voronoi diagrams.

In [15]:
clf;
imageplot(Q);
colormap(jet(256));


Exercise 2

Display the level sets.

In [16]:
exo2()

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