- The function MSFM2D/MSFM3D calculates the shortest distance from a list of points to all other pixels in an 2D or 3D image, using the Multistencil Fast Marching Method (MSFM). This method gives more accurate distances by using second order derivatives and cross neighbors.

- The function Skeleton will calculate an accurate skeleton (centerlines) of an object represented by an binary image / volume using the fast-marching distance transform.

- The function Shortestpath traces the shortest path from start point to source point using Euler or Runge Kutta 4 in the 2D or 3D distance map.

Implementation:
The 2D fast marching method is implemented in both Matlab-code and c-code. The c-code uses a custom build unsorted binary tree minimum search which out performs a normal binary sorted tree. The c-code is more than 500 times as fast as the matlab-code (compiled with the Microsoft Visual compiler).

We compared the results of our implementation with the results in the paper:
- Normal fast marching 1th order, exact the same results.
- 2th order, significant smaller errors than in the paper.
- Multistencil 1th order, larger errors than in the paper
- Multistencil 2th order, significant worse results than published in the paper. (Note : Our results are in accordance to other existing implementations )

The last version of our code produces better result than in the paper or other literature. This is achieved by solving the polynomial roots using all the available information, as described by the comment of Olivier Roy below.

I believe by creating groups of the starting points one could use parfor (on those groups) to compute distance maps and take advantage of multiple CPU cores with each core working on a group of the distance points.

Excellent. Just what I need for skeletonisation of 3D images. Has saved me lots of time!

Just one thing I am wondering... Is it possible to restrict the skeletonisation to a single, most-probable, branch? All my images are of a single branch but, depending on which threshold I use, the algorithm gives me multiple branches.

Hi every one.
I wrote FMM code in C++ by myself but for large number of grids, I think it take too much time. Would you please tell me know that typically how long it should take for running the efficient code in a mesh that contains 1 million grids.(100*100*100).

For a sake a fast computation, I ran the example given in the skeleton file with a reduced version of the vessels3d =>V=V(1:128,1:128,1:128);

After final completion, if you display the skeleton along with an isosurface of the volume of interest (V), and rotate the figure, the skeleton seems to connect the three separated parts into one skeleton.

I think there should be some sort of check on whether the skeleton is passing a background area where there is no foreground voxels representing the blood vessel.

Unless I am doing something wrong, and if so, I will immediately apologize to you.

I also discovered a tiny mistake, easily solvable, in the example of your skeleton code (line 42 - commented):

I find a large difference in my results between using and not using cross-neighbours, and would like to know what exactly the cross-neighbours are that you use - as I can not find a reference for them anywhere.
Are they the diagonal neighbours calculated via directional derivatives (Hassouna 2007)?

Thanks for sharing code. It is faster one than what I used for my research.

One problem I found: when I used constant speed, shortestpath code will crash. Also, shortestpath for 3D case (just like 2D since constant value in y direction) is not consistent with 2D case. I can send your my results if you want to take a look at them.

Excellent job!
But I have a problem when I test it on my data, local tumor vascular which is unconnected volume.However,The result skeleton was turned out to be connected and passed through two separated vessels.How can I fix this?

Great submission thanks. The tree structure you use is very efficient.

I compared, as you did, the accuracy of your implementation with the results reported in M. Sabry Hassouna et al. "Multistencils Fast Marching Methods: A Highly Accurate Solution to the Eikonal Equation on Cartesian Domains". Not sure exactly what they do but I found that the accuracy depends a lot on how the results of the two stencils are combined (which is somewhat arbitrary since we do not know a priori which stencil provides the most accurate result).

To improve the accuracy here is the trick: instead of computing the distance with the first and second stencils separately, simply sum the corresponding second order polynomials and solve the resulting second order equation. In other words, simply replace

*Daniela
The speed function may contain all values larger then zero.
But in practice you have numerical round offs, and because the next "time front" always depend on the old "time front", this error will grow and can sometimes become very high.

The code is easy to understand, but the speed function must be between [1e-8,1], otherwise you get a complex number to value of T, where T is arrival time - this is not correct. Anybody observe/solve that? *Notice that such a constraint for F is theoretically wrong.*

Nice submission, works perfectly, and well commented. Thank you!
One thing I was wondering:
Is it possible to give a maximum distance to compute, and not fill the entire image with correct distances? In my problem that would speed up computation considerably.

Furthermore, I deleted the line
if(itt==652221) { printf("569 \n"); }
in msfm2d.c as it put my command window full with 569s.