File Exchange

image thumbnail

Multiphase level set image segmentation

version (14.7 MB) by Ismail Ben Ayed
performs multiphase level set image segmentation according to various formulations


Updated 18 Nov 2010

View License

This Matlab/C code contains routines to perform level set image segmentation according to:

(1) various multiphase (multiregion) formulations, including a fast scheme where the computation load grows linearly with the number of regions and,

(2) various region-based image descriptions which generalize the standard piecewise constant Chan-Vese model; the descriptions include Gamma distribution models for image data corrupted by multiplicative noise as in remote sensing synthetic aperture radar (SAR), and medical imaging ultrasound. Also included is kernel mapping as an alternative to explicit image modeling.

Complete details on usage and compilation can be found in the enclosed pdf file (Readme.pdf). The functions were tested on the following versions of MATLAB and C.

MATLAB version: (R2008b)

C compiler: Lcc-win32 C 2.4.1

The code implements the level set methods in the following papers (the papers are included in the package):

I. Ben Ayed, A. Mitiche, and Z. Belhadj, “Multiregion level set partitioning on synthetic aperture radar images,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 27, no. 5, pp. 793–800, 2005.

M. Ben Salah, A. Mitiche and I. Ben Ayed, “Effective Level Set Image Segmentation with a Kernel Induced Data Term,” IEEE Transactions on Image processing, vol. 19, no 1, pp. 220-232, 2010.

I. Ben Ayed, A. Mitiche, and Z. Belhadj, “Polarimetric image segmentation via maximum likelihood approximation and efficient multiphase level sets,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 28, no. 9, pp. 1493–1500, 2006.

I. Ben Ayed, A. Mitiche, “A Partition Constrained Minimization Scheme for Efficient Multiphase Level Set Image Segmentation,” IEEE ICIP 2006, pp. 1641-1644.

I. Ben Ayed and A. Mitiche, “A region merging prior for variational level set image segmentation,” IEEE Transactions on Image Processing, vol. 17, no. 12, pp. 2301–2313, 2008.

A. Mansouri, A. Mitiche, and C. Vazquez, “Multiregion competition: A level set extension of region competition to multiple region partioning,” Computer Vision and Image Understanding, vol. 101, no. 3, pp. 137–150, 2006.

C. Vazquez, A. Mitiche, Ismail Ben Ayed, “Image segmentation as regularized clustering: a fully global curve evolution method,” IEEE ICIP 2004, pp. 3467-3470.

Formal and complete details on the implementations as well as on the derivation of the level set evolution equations from various energy functional types can be found in the book “Variational and Level Set Methods in Image Segmentation, by A. Mitiche and I. Ben Ayed, 2010, Springer, 1st edition”

Cite As

Ismail Ben Ayed (2021). Multiphase level set image segmentation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)


shunguang wu

One reason leads to Matlab crash is that the last line of code in LevelSet.m should be
Seg2_Stim(22, structure). ( the original one is Seg2_Stim(20, structure) ), If you looks at the mexFunction() in Seg2_Stim.c, argv[22] is used.

After that fix, the code can be built and run in matlab 2017a with MEX configured to use 'Microsoft Visual C++ 2015 Professional (C)'

Ander Biguri

Compiling with VS C++ compiler generates various errors, such as the redefinition of the max() function (why do this?) or the lack of M_PI. Even by changing that and compiling, the code errors.

Braiki Marwa

Error message is displayed in matlab as....Undefined function 'Seg2_Stim' for input arguments of type 'struct'.

xiuying yuan

matlab crash...

dd guan

compiles with matlab2012a on Ubuntu 14.04 with lcc, have some errors

mog sam

Error message is displayed in matlab as....Undefined function 'Seg2_Stim' for input arguments of type 'struct'.

ujjwal baid


ujjwal baid

Error message is displayed in matlab as....Undefined function 'Seg2_Stim' for input arguments of type 'struct'.


Very good codes ... but Matlab crashes sometimes with errors (MATLAB issues a segmentation violation and stack trace).
I have Matlab R2012a and compiled with Visual Studio 2010.

Does someone get this issue ?


Martin Rajchl

Compiles and runs with Matlab 2013A on Ubuntu 14.04 x64 with gcc 4.6.

There was an issue with a free(p) in Seg2_Stim.c on line 775: free(p); comment this out to get it to work.

Super implementation, just saved me a lot of time.


Problem with compiling not using the lcc 2.4.1 compiler can be solved by adding;

#define M_PI 3.141(etc)

to the levelset.h file definitions.

uma mahessh

i am not able to run the code,getting me..


Very useful



Thank you for your code.
I can't run the program too.



hi ,thanks for your work.but i find i can not run the program also .

Suruchi goel

I have the same problem as mentioned by Francesco. Unable to run the code since could not compile .c files and locate lcc compiler for 64 bit.
Kindly suggest.


your code seems very promising and I like the professional way in which the documentation is cured.

I have a problem though, which is likely more general: Matlab 64bit doesn't come with LCC compiler, and in fact this is not supported at all, so I can't find a way around it to compile it.

Any suggestions? Could you provide pre-compiled routines somewhere?


MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!