Code covered by the BSD License  

Highlights from
Image segmentation - multiscale energy-based level sets

5.0 | 7 ratings Rate this file 58 Downloads (last 30 days) File Size: 53.3 KB File ID: #31975
image thumbnail

Image segmentation - multiscale energy-based level sets


tudor dima (view profile)


27 Jun 2011 (Updated )

Segmentation using active contour without edges and multi-scale acceleration. GUI included

| Watch this File

File Information

This toolbox implements an energy-based segmentation algorithm that uses
finite-difference based level set evolution. (See [1], [2]).
Multiscale control of the curve evolution is implemented -- this greatly reduces
the sensitivity to initialization as well as improves the execution speed
by factors of 10-1000 and even more([3]).

Given a segmentation problem, one can use this GUI in order to find the
proper parameters that will yield the desired partition for the class of images used.
The functions in the toolbox can be then re-used for a scripting algorithm, if desired.

This is not a full multigrid algorithm, the scale navigation is provided in 'manual'
mode, for "image learning". Once you get the hang of it, you can then code that
bit in. On the same line, the error is calculated and shown, but no decision is
taken, the iteration control is also left on "manual".

For details on the algorithm see the references at the end.

From the GUI one is able to:
 - load data and save intermediate states using the Load/Save menu
 - choose the segmentation parameters (Mu, Lambda+, Lambda- , dt, Nu)
 - iterate(relax) a chosen number of steps
 - prolong, restrict, redistance the level set
 - visualise the current solution
 - inspect the error (and more goodies as error function gradient, residue, etc.)
 - set various options (levelset initialization style, regularization, scale depth, #steps)

For more details on the interface and implementation see the appropriate help sections in the GUI.

[1] R. J. LeVeque - "Finite Difference Methods
for Differential Equations" September, 2005
[2] T. Chan and L. Vese, "Active contours without edges"
IEEE Trans.Img.Proc., vol. 10, pp. 266–277, 2001.
[3] W. L. Briggs, V. Emden Henson, S. F. McCormick
"A Multigrid Tutorial", SIAM, Philadelphia, 2001.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements In case bwdist.m is not in your distribution you can use the provided built-in function.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
09 Jul 2013 muthu Kumar  
25 Jun 2012 tudor dima

tudor dima (view profile)

While drawing the initial contour follow the messages in the command window.

At load time (whether from image or .mat file) keep scale depth at 0 if you want to start at the finest resolution. (I suspect you load a ~72x72 array and have kmax set at 3?)

Will look into adding capability to load an initial contour. What is in there already is the ability to save the level-set function and re-use it. (Say once you have input a complicated initialization, you don't want to go through it every time, so you can save it and load it over. However, the image data has to be of the same size.

Comment only
19 Jun 2012 Javier

Javier (view profile)


another question: when I load a .mat with a double image (the variable is g0 as commented in the code) and then I press "DO Iter" I only see 9 pixels of my image. What can I do?


18 Jun 2012 Javier

Javier (view profile)


thanks for sharing the code. I'm having troubles to create a manual initial contour. I select the option Ini. Method "draw" and then I press the button "DO Iter!" but I can't select points with the mouse. What am I doing wrong?

Another question: If I have already the initial contour as a binary mask, can I avoid the function "iniMembrane"?

Thank you very much

25 May 2012 tudor dima

tudor dima (view profile)

Hi, Marcos,

For starters, there is a very short description under Help | Buttons.

You can try the Chan-Vese paper I referenced higher in the abstract (no. [2])

The normalization you mention is done precisely in order to decouple the parameters value from the actual image values (which could come as uint8, uint16, 0-1, or any other data).

Comment only
24 May 2012 Marcos Belmonte

Hi,I'm doing my final project of the degree and I haven't a lot of experience so, it's hard for me to follow so much lines of code. I was wondering if you had a paper explaining this guide: the differential equations you employed for the method or something like this. I have proved your method and I really like the results but I want to understand how the parameters affect in order to get better results.

By the way, my images are double and of 16 bits and
approx at lines 840-841 I see:
MaxGVal = max(g(:));
g = g * (255/MaxGVal);

Does it affect my intensity values? It is necessary? Thank you very much!

26 Apr 2012 Marcos Belmonte

You warned me about blank spaces in a previous comment but I forgot it, thanks again.

21 Apr 2012 tudor dima

tudor dima (view profile)

Hi, Marcos
Check if your current location (where you installed this toolbox) contains any spaces. (it happends on Windows, .../My Documents/ ...)
If this is the case try to move it to a space-less location.
If for some reason this isn't possible try this hack, until I post the new version :

Replace line 307 with cd(attData.myData.loc.ImageDir)

Comment only
12 Apr 2012 Marcos Belmonte

Hi, thanks for the answer. Now I'm trying to use images as jpg but with the button Load Image File appears immediatly the same error as I posted before, without appearing any menu to select a file. What can be the problem and then, how can I place a circle of the radius I want and where I want for an initial seed?


24 Mar 2012 tudor dima

tudor dima (view profile)

This box uses Matlab imread.m, I suspect you could find a Dicom reader on the exchange and either plug it in or convert your images to .jpg, .png, etc.

Be careful with blank spaces in your directory, though, the error above seems to stem from there. I am planning to allow this in a future release.

Comment only
22 Mar 2012 Marcos Belmonte

Hi, thanks for sharing your code. I have a problem loading dicom images with Load Image File. First I have run ini.m and then segm_energy_LS, what can be the problem?

??? Error using ==> cd
Too many input arguments.

Error in ==> segm_energy_LS>fLoadData at 307
eval(['cd ' attData.myData.loc.ImageDir])

??? Error while evaluating uimenu Callback

Thanks very much

30 Sep 2011 tudor dima

tudor dima (view profile)

@Qwuasi Moore - I am not sure I understand what you mean. The evolution rule is solved discreetly using an FD method, I suppose (and this is just a wild guess) that it would be possible to write an FEM solution. I assume you'd encounter similar issues (mainly execution speed, and the infamous convergence issues)

Depending on how your images look like you might want to choose your segmentation method. This one in particular is powerful when dealing with fuzzy and/or incomplete contours, low gradients, etc. (f.i. environments with noise and jitter)

Comment only
30 Sep 2011 Pooja

Pooja (view profile)

can I use these codes for Brain tumor segmentation?

Comment only
21 Aug 2011 Qwuasi Moore

Great...Is it possible to do it with FEM?

Comment only
28 Jun 2011

better description

10 Jul 2011

Undersampling of the image to be segmented using splines.
Better help, fixed some window sizes.

13 Aug 2011

can now change on the fly the scale depth kMax (before one had to reload the file)

16 Aug 2011


23 Apr 2012 - 22.04.2012
          allow spaces in image directory names
          add handy reset button (before in pull-down menu)
          better help, split by section

23 Apr 2012 - 22.04.2012
          allow spaces in image directory names
          add handy reset button (before in pull-down menu)
          better help, split by section

25 Jun 2012


19 Feb 2013

v.1.0.1 - allow saving and loading of masks and level-set functions
- improved workflow and help comments

Contact us