swig error after upgrading to 5.0

itk_seed = itk.GetImageFromArray(init_levelset.astype(np.float32))

InternalImageType = itk.Image[itk.F, 3]

geodesicActiveContour = itk.GeodesicActiveContourLevelSetImageFilter[InternalImageType,InternalImageType,itk.F].New(itk_seed)
geodesicActiveContour.SetPropagationScaling(10.0)
geodesicActiveContour.SetCurvatureScaling(1.0)
geodesicActiveContour.SetAdvectionScaling(1.0)
geodesicActiveContour.SetMaximumRMSError(0.02)
geodesicActiveContour.SetNumberOfIterations(60)
geodesicActiveContour.SetFeatureImage(itk_img_sigmoid)
geodesicActiveContour.Update()

itk_GAC = geodesicActiveContour.GetOutput()

I used this piece of code for a 3d level set segmentation step. It worked okay previously. After updating to 5.0 today, I got the following error:

AttributeError Traceback (most recent call last)
in
5 InternalImageType = itk.Image[itk.F, 3]
6
----> 7 geodesicActiveContour = itk.GeodesicActiveContourLevelSetImageFilter[InternalImageType,InternalImageType,itk.F].New(itk_seed)
8 geodesicActiveContour.SetPropagationScaling(10.0)
9 geodesicActiveContour.SetCurvatureScaling(1.0)

c:\users\jianxuc\appdata\local\continuum\anaconda3\envs\segmenter\lib\site-packages\itkLazy.py in getattribute(self, attr)
42 module = self.__belong_lazy_attributes[attr]
43 namespace = {}
—> 44 itkBase.LoadModule(module, namespace)
45 for k, v in namespace.items():
46 setattr(self, k, v)

c:\users\jianxuc\appdata\local\continuum\anaconda3\envs\segmenter\lib\site-packages\itkBase.py in LoadModule(name, namespace)
61 else:
62 swig = namespace.setdefault(‘swig’, imp.new_module(‘swig’))
—> 63 swig.dict.update(this_module.swig.dict)
64
65 # don’t worry about overwriting the symbols in namespace – any

AttributeError: module ‘ITKLevelSets’ has no attribute ‘swig’

BTW, is there a more detailed documentation about new pythonic interface? For example, I want to use itk.GeodesicActiveContourLevelSetImageFilter. What is the pythonic way to use it?

Many thanks,
Jianxu

Hi Jianxu,

The initial release of the ITK 5.0.0 Python packages contained a bug that may be the source of your problem. Please try

python -m pip install --upgrade itk

to install the itk-5.0.0.post1 Python package.

The code can replace by this single call:

itk_GAC = itk.geodesic_active_contour_level_set_image_filter(itk_seed,
        feature_image=itk_img_sigmoid,
        propagation_scaling=10.0,
        curvature_scaling=1.0,
        advection_scaling=1.0,
        MaximumRMSError=0.02,
        number_of_iterations=60)

Notice than the corresponding API is easily implied, we can use snake case, we do not need to specify the filter type, and a single call replaces instantiating the filter, setting its parameters, calling .Update(), and calling .GetOutput().

An overview of the new interface can be found in the ITK 5.0 Beta 1: Pythonic Interface release announcement.

@hjmjohnson is leading a major update to the ITK Sphinx Examples. This is currently a work in progress, but the plan to improve these to use the new interface as the dust settles.

1 Like