Migrating SimpleITK 1.x to 2.x

194 views Asked by At

I'm working on a project on GitHub that was made with Python 2.7 (https://github.com/AIM-Harvard/DeepCAC)

I've made most relevant changes as to update it to Python 3.7, but I'm fixed on an error message regarding simpleITK.

Error message:

TypeError: Execute() takes 2 positional arguments but 10 were given

It stems from this code:

res_filter = sitk.ResampleImageFilter()

----> img_sitk = res_filter.Execute(img_sitk, curated_size, sitk.Transform(), method, img_sitk.GetOrigin(), curated_spacing, img_sitk.GetDirection(), 0, img_sitk.GetPixelIDValue()) 

According to the simpleITK document on switching from 1.x to 2.x (version that is available with python 3.7) it should be done like this (https://simpleitk.readthedocs.io/en/master/migrationGuide2.0.html#filter-s-execute-method) but I can't quite grasp it.

Can someone help out? Thanks

1

There are 1 answers

0
Dave Chen On

It looks like you're trying to use the procedural version, Resample, not the class version, ResampleImageFilter.

You can see the documentation for the Resample function here: https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#aadbb243c10d1aedea8e955e8beda4df0

You want to the second version of Resample. So your code would look like this:

img_sitk = sitk.Resample(img_sitk, curated_size, sitk.Transform(), method, img_sitk.GetOrigin(), curated_spacing, img_sitk.GetDirection(), 0, img_sitk.GetPixelIDValue()) 

If you want to use the ResampleImageFilter, you would set all the parameters using the filter's various Set methods, and then just call the Execute method with the input image as the only parameter.