Calculate the signed distance function of a set described by its level-set function. The array phi must contain the values of the level-set function on a rectangular grid with spacing h.
The initial distances are approximated using ls_init_narrowband,
and then fastmarching is used to propagate them to all other points
on the grid.
It may be a good idea to use ls_normalise on the level-set function
before using this method, to prevent almost-zero values from underflowing
due to the performed calculations.
See also: fastmarching, ls_distance_fcn, ls_solve_stationary, ls_normalise.
The following code
n = 100;
x = linspace (-10, 10, n);
h = x(2) - x(1);
[XX, YY] = meshgrid (x, x);
phi0 = atan (ls_union ((XX.^2 + (YY - 5).^2) - 20, ...
(XX.^2 + (YY + 5).^2) - 20));
%phi0 = XX.^2 / 1.3^2 + YY.^2 - 1;
d = ls_signed_distance (phi0, h);
figure ();
subplot (1, 2, 1);
contour (XX, YY, phi0);
title ("Initial");
colorbar ();
axis ("equal");
subplot (1, 2, 2);
contour (XX, YY, d);
title ("Signed Distance");
colorbar ();
axis ("equal");
Produces the following figure
| Figure 1 |
|---|
![]() |
Package: level-set