active contour without edge

python
(Jianxu Chen) #1

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

https://www.insight-journal.org/browse/publication/322
http://insight-journal.org/browse/publication/323

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,
Jianxu

(Jon Haitz Legarreta Gorroño) #2

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.

HTH.

1 Like
(Jianxu Chen) #3

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

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

https://itk.org/Doxygen/html/classitk_1_1ScalarChanAndVeseLevelSetFunction.html

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?

thanks!

(Jon Haitz Legarreta Gorroño) #4

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.

HTH.

1 Like
(Jianxu Chen) #5

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,
jianxu

(Jon Haitz Legarreta Gorroño) #6

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.

HTh

1 Like
(Jianxu Chen) #7

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

(Jianxu Chen) #8

@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
PYTHON_LIBRARY_DEBUG PYTHON_LIBRARY_DEBUG-NOTFOUND
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?

Thanks!

(Jon Haitz Legarreta Gorroño) #9

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

(Bradley Lowekamp) #10

Hello,

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.

(Francois Budin) #11

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
(Bradley Lowekamp) #12

SimpleITK has the “ScalarChanAndVeseDenseLevelSet” already in the distribution.

(Jianxu Chen) #13

@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 http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/300_Segmentation_Overview.html

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()
lsFilter.SetMaximumRMSError(0.02)
lsFilter.SetNumberOfIterations(20)
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 “test_ac.py”, line 110, in
ls = lsFilter.Execute(init_levelset, itk_img_smooth)
File “/home/jianxuc/anaconda3/lib/python3.6/site-packages/SimpleITK/SimpleITK.py”, 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)
gradientAnisotropicDiffusionFilter.SetNumberOfIterations(5)
gradientAnisotropicDiffusionFilter.SetTimeStep(0.0625)
gradientAnisotropicDiffusionFilter.SetConductanceParameter(1.2)
gradientAnisotropicDiffusionFilter.Update()
itk_img_smooth = gradientAnisotropicDiffusionFilter.GetOutput()

Any thoughts? Or any advice on documentation or intructions?

Many thanks!

(Bradley Lowekamp) #14

Hello,

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.

(Bradley Lowekamp) #15

Here is a brief example:

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

fastMarching = sitk.FastMarchingBaseImageFilter()
fastMarching.AddTrialPoint([160,190,0])
radius = 10
fastMarching.SetStoppingValue(radius+5)
initial_ls = fastMarching.Execute(img*0+1)-radius

lsFilter = sitk.ScalarChanAndVeseDenseLevelSetImageFilter()
lsFilter.SetMaximumRMSError(0.0)
lsFilter.SetNumberOfIterations(500)
lsFilter.SetLambda1(1)
lsFilter.SetLambda2(1)
lsFilter.SetEpsilon(1.0)
lsFilter.SetCurvatureWeight(1.0)
lsFilter.SetAreaWeight(0.0)
lsFilter.SetReinitializationSmoothingWeight(0.0)
lsFilter.SetVolume(0.0)
lsFilter.SetVolumeMatchingWeight(0.0)
lsFilter.SetHeavisideStepFunction(lsFilter.AtanRegularizedHeaviside)
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!

1 Like
(Jianxu Chen) #16

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.

https://simpleitk.readthedocs.io/en/master/Documentation/docs/source/filters.html

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,
Jianxu

(Bradley Lowekamp) #17

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

Here is SimpleITK doxygen:
https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ScalarChanAndVeseDenseLevelSetImageFilter.html

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

I look forward to your demos!