File Exchange

image thumbnail

Sparse Field Methods for Active Contours

version 1.2 (50.8 KB) by

Very fast implementation of level sets. 2D and 3D support, written in C++/MEX with MATLAB wrapper.

7 Ratings



View License

Active contour methods for image segmentation allow a contour to deform iteratively to partition an image into regions. Active contours are often implemented with level set methods because of their power and versatility. The primary drawback of level set methods is that they are slow to compute. This code implements the very efficient sparse field method (SFM) proposed by Whitaker. Specifically, the well-known Chan-Vese energy is minimized.
To run the MATLAB demo, simply unzip the file and run:


at the MATLAB prompt. On the first run, this will compile the MEX code on your machine and then run the demo. If the MEX compile fails, please check your MEX setup. The demo is for a 2D image, but the codes work for 3D images as well.

My hope is that other researchers wishing to quickly implement Whitaker’s method can use this information to understand the intricacies of the algorithm and enjoy the same SUBSTANTIAL speed-ups I have.

For a full technical report detailing the algorithm and implementation, please check this post:

[ ]

Comments and Ratings (12)


wang (view profile)

it seems that the code lack the definition of function fat_contour in 'visualize_phi'.

how is it definied?

G. Sken

G. Sken (view profile)

is there any possibility to provide your code with a segmentation threshold ?
say I like to segment to 10 one gray volume/image like this :
[xx,yy,zz] = meshgrid(1:side,1:side,1:side);
c=[h_side h_side h_side];% centre in the midle
% calculate distance from center of the cube
rr = sqrt( (xx-c(1)).^2 + (yy-c(2)).^2 + (zz-c(3)).^2 ); % gray volume

Lipeng Jiu

How can I implement this as 3D level set?

Vincent Gigot

It does not seem to work on my Matlab version (R2012b).
Following error message that seems to comme from the compilation, I'va got the compiler toolbox :
"""Compiling sfm_chanvese_mex...
Error: Could not detect a compiler on local system
which can compile the specified input file(s)
Error using mex (line 206)
Unable to complete successfully.

Error in compile_sfm_chanvese (line 6)
mex sfm_chanvese_mex.cpp llist.cpp energy3c.cpp lsops3c.cpp

Error in sfm_chanvese (line 26)

Error in sfm_chanvese_demo (line 18)
[seg] = sfm_chanvese(img,mask,iterations,lambda);"""


Robert (view profile)


Anusha (view profile)

How can I implement this as 3D level set?

Alex Kararg

Could you please help on how I could use your algorithm with 3D images? I have the x,y,z coordinates of the points. I am kind of new to matlab.

Shawn Lankton

Shawn Lankton (view profile)

Thanks Sebastien. The bug is FIXED now.

Sebastien PARIS

Ok I found the bug. Please add "return newll;" in the end of ll_create() function ... Compile fine with Intel ICC right now (around 41% faster than MSVC for my laptop)

Please also compile with the -v option to verbose unused variables and remove them.

Sebastien PARIS

Works fine. Thank you. Do you plan to include "multiphase" version ?. One point Segmentation fault when compiled with Intel compiler, ok with LCC or MSVC ... I'll look inside when I'll have time ...

Romeil Sandhu

This is excellent! Very nicely written, and easy to integrate with an already on-going project. It does what it says -- provides a fast implementation of level sets. Great job.



Added BSD License


Fixed some bugs, and updated the demo script. Thanks to Sebastien Paris for pointing out a bug in the comments! FIXED.


Fixed bug in the prototype for ls_iteration()

MATLAB Release
MATLAB 7.7 (R2008b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video