Installing toolboxes and setting up the path.

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/');

Non-linear Second-order Parabolic PDEs

This tour defines PDE flows that are non-linear extension of the heat equation. Non-linearity is crucial to produce edge-aware
flows that do not blur the edges.

It is also important to produce contrast invariant and affine invariant flows.

These flows can be written as \[ \pd{f_t}{t}(x) = G(\nabla f_t(x), \nabla^2 f_t(x)). \] with \(f_0\) defined at time \(t=0\)
(whith the slight modification that a blurring is introduced in the Perona-Malick flow to stabilize it).

They are discretized in space by considering a discrete image of \(N = n \times n\) pixels.

n = 256;

We use finite difference operators \(\nabla\) and \(\text{div}=-\nabla^*\) with periodic boundary conditions.

Load an image \(f_0 \in \RR^N\), that will be used to initialize the flow at time \(t=0\).

The flow is discretized in time using an explicit time-stepping \[ f^{(\ell+1)}(x) = f^{(\ell)}(x) + \tau G(\nabla f^{(\ell)}(x),
\nabla^2 f^{(\ell)}(x)). \] Here \(\tau>0\) should be small enough, and \(f^{(\ell)}\) produces an approximation of \(f_t\)
at time \(t=\ell\tau\).

Mean Curvature Flow

In the limit that \(\la \rightarrow +\infty\) and \(\si \rightarrow 0\) the Perona-Malick flow becomes \[ \pd{f_t}{t} = \text{curv}(f_t)
\] where \[ \text{curv}(f) = \text{div}\pa{ \frac{\nabla f}{\norm{\nabla f}} }. \] One can show that \(\text{curv}(f)(x)\)
is the curvature at location \(x\) of the level set \(\enscond{y}{f(y)=f(x)}\).

This flow is the gradient descent flow associated to the total variation \[ J(f) = \int_{\RR^2} \norm{\nabla f(x)} d x, \]
which can be extended to non-smooth functions of bounded variations. Indeed, a (sub)gradient of \(J\) is \( -\text{curv}(f)
\).

A closely related flow is the so-called mean curvature flow \[ \pd{f_t}{t} = \norm{\nabla f_t} \text{curv}(f_t). \] One can
show that this flow is contrast-invariant. This means that for any non-decreasing function \(\phi : \RR \rightarrow \RR\),
\(\phi \circ f_t\) is also a solution of the PDE (possibly up to a re-parameterization of the time variable).

One can show that any contrast-invariant flow can be written as \[ \pd{f_t}{t} = \norm{\nabla f_t} \psi( \text{curv}(f_t)
) \] for a non-decreasing function \(\psi : \RR \rightarrow \RR\).

Implement the curv operator. We use a small \(\epsilon\) to avoid division by 0.