active contour without edge

I am trying to build a segmentation module using the following two algorithms.

Is it possible for me to download the source C++ code published there and re-build them locally so that it can be used in the new ITK 5.0 pythonic way?

Many thanks,

Not sure whether they have been integrated/renamed in ITK, since ITK core does have a few filters implementing level set and active contour methods. You’d may be need to have a look at the Review folder of the legacy releases, and the release notes. Other experienced users of such filters may be able to confirm.

If the core filters do not match your needs, and these do, chances are that you’ll need to update them (i.e. you are likely to get build warnings, errors) since they are 10 years old, tested against 10-year old compilers, and ITK 5.0 is quite different from ITK 3.x, which was most probably used at the time.

But that is definitely a worthwhile effort that will benefit the community :+1:. Making them available as a remote module would be an option.

Also, if you want to use them in Python, you’ll need to write the Python wrappings, since they are lacking the Python wrappers.


1 Like

@jhlegarreta, thanks for your swift reply. that is very helpful.

indeed, i found the following one as an ITK ReviewModule.

i think this is what I am looking for. What does ITK ReviewModule imdicate? means they are not ready to use, or can be used but just not in core yet?


You’re welcome @Jianxu_Chen !

The Review module contain classes that were initially submitted to the Insight Journal, and were/are in theory in the process of being reviewed/tested. These modules are available when the corresponding CMake flag is set to ON.

These classes eventually make it to the toolkit’s core when they have been thoroughly tested/their review period is considered to have been sufficient.

So to answer to your question:

  • Yes, they are ready to be used. But you may experience some glitches, depending on your data, your platform or your requirements. If you do, providing fixes is more than welcome.
  • They are not part of the core, but they may eventually be. Even if they dwell in the Review module, they are equally relevant and important to the toolkit.


1 Like

thanks for the info @jhlegarreta. i would be happy to be a tester of this module and related ones.

i just poked it around. do you know an instruction on how to compile or install itk with review modules turned on? i did a regular pip install to install itk. but it seems like the module cannot be found through python.

Or, maybe the review modules are installed, but just don’t have a python wrapper? any advice? if there is a general instruction on building python wrapper for itk modules, i would be happy to implement one.

thanks again,

I’d dare to say that the PyPI wheels do not include the review modules; @fbudin please correct me if I’m wrong.

In that case, you’ll need to build the package yourself. The ITKPythonPackage repository may be useful in that task. Uploading the package may benefit others !

In order to know if the class you are looking for has a Python wrapping, you’ll need to have a look at the wrapping folder of the Review module. In this case, the class you are interested in is wrapped. Testing and proposing fixes as necessary is welcome.


1 Like

great! thank you so much! i will test it out and keep people updated on my progress.

@jhlegarreta, update:

I read through the instructions and tried to build ITK and the python wrappers. But, I kept getting the following error:

CMake Warning at Wrapping/Generators/Python/CMakeLists.txt:14 (message):
Python executable (“3.6.1”) and library ("") version mismatch.

what I set:

PYTHON_EXECUTABLE /home/jianxuc/anaconda3/bin/python
PYTHON_INCLUDE_DIR /home/jianxuc/anaconda3/include
PYTHON_LIBRARY /home/jianxuc/anaconda3/lib/python3.6
PY_SITE_PACKAGES_PATH /home/jianxuc/anaconda3/lib/python3.6/site-packages/

To my understanding, cmake does not recognize the library version. Any thoughts or suggestions?


Not sure about it (I seldom build the Python wrap), but the PYTHON_LIBRARY_DEBUG variable may need to be set also.


Just an FYI, the classes submitted in that old IJ article were a predecessor the the “ITKLevelSetsv4”.

Here is an example of using the newer levelset framework for “Chan and Vesel” segmentation:

IMHO, this is a class in review that likely should go into a remote/external module because it’s successor is already in ITK.

Thanks @blowekamp for pointing @Jianxu_Chen to the newer implementation. The new classes are not wrapped in Python (there is not wrapping folder here). To make these classes avaiable in Python, one would need create a pull-request to add those wrapping files. Information about how to create wrapping files can be found in the Software Guide and by looking at existing wrapping files for other modules (in the wrapping subfolder).

@blowekamp: If the filter in the Review folder is a duplicate, it would indeed make sense to remove it from ITK. Since we just released ITK v5, it is probably too late to just remove it, but moving it to an remote module seems to me to be the appropriate solution.

1 Like

SimpleITK has the “ScalarChanAndVeseDenseLevelSet” already in the distribution.

@blowekamp thanks for pointing that out. That’s really helpful.

But, I am having a hard time to find any instruction on how to use it. What I found is

But, it does not have a demo of ScalarChanVese, only saying it is supported. I tried a few different ways, my current one is

lsFilter = sitk.ScalarChanAndVeseDenseLevelSetImageFilter()
ls = lsFilter.Execute(init_levelset, itk_img_smooth)

But, I cannot any public member function to set other parameters like number of iterations and RMSError. I think there should be some paramter to control the curvature? Anyway, above code still gives me

Traceback (most recent call last):
File “”, line 110, in
ls = lsFilter.Execute(init_levelset, itk_img_smooth)
File “/home/jianxuc/anaconda3/lib/python3.6/site-packages/SimpleITK/”, line 58659, in Execute
return _SimpleITK.ScalarChanAndVeseDenseLevelSetImageFilter_Execute(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function ‘ScalarChanAndVeseDenseLevelSetImageFilter_Execute’.
Possible C/C++ prototypes are:
itk::simple::ScalarChanAndVeseDenseLevelSetImageFilter::Execute(itk::simple::Image const &,itk::simple::Image const &)
itk::simple::ScalarChanAndVeseDenseLevelSetImageFilter::Execute(itk::simple::Image const &,itk::simple::Image const &,double,uint32_t,double,double,double,double,double,double,double,double,itk::simple::ScalarChanAndVeseDenseLevelSetImageFilter::HeavisideStepFunctionType,bool)

Other info:
raw is a np.float32 3D numpy array.

itk_img = itk.GetImageFromArray(raw)
gradientAnisotropicDiffusionFilter = itk.GradientAnisotropicDiffusionImageFilter.New(itk_img)
itk_img_smooth = gradientAnisotropicDiffusionFilter.GetOutput()

Any thoughts? Or any advice on documentation or intructions?

Many thanks!


We are in need of writing more SimpleITK LevelSet examples. I’ll look into this one.

What is the output of lsFilter.SetCurvatureWeight? or dir(lsFilter)?

From your error message, I’m going to guess that init_levelset is not a SimpleITK image. Minimal example are very important for debuting and staring problems.

Here is a brief example:

img = sitk.ReadImage("cthead1.png", sitk.sitkFloat32)

fastMarching = sitk.FastMarchingBaseImageFilter()
radius = 10
initial_ls = fastMarching.Execute(img*0+1)-radius

lsFilter = sitk.ScalarChanAndVeseDenseLevelSetImageFilter()
output = lsFilter.Execute(initial_ls, img)

This segments the whole head from the background. I was hoping to be able to just segment the cerebellum region in the the slice, but I’d need to review the paper again.

Hope this helps!


hi @blowekamp, thanks a lot. it is really helpful. After tweaking the image types a little bit in my problem, it is working now.

I found that the links in page below are wrong.

When I clicked the ScalarChanVese filter, it links to the ReviewModule, instead of the simple Module. In the ReviewModule, the list of functions .SetXXXXX() is very different. That is what made me so confused at the beginning.

Anyway, it makes sense to me now. I am trying to prepare a more exhaisted list of demos for different level set modules and will share it. Hope it can he helpful for other people.

Thanks again,

The links from SimpleITK’s filter index should go to SimpleITK doxygen. Thanks for the report.

Here is SimpleITK doxygen:

Many of the additional methods to the simpelitk filter come from the underlying LevelSetFunction.

I look forward to your demos!