Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using WriteParameterFile #66

Closed
tfunck opened this issue May 18, 2018 · 1 comment
Closed

TypeError when using WriteParameterFile #66

tfunck opened this issue May 18, 2018 · 1 comment

Comments

@tfunck
Copy link

tfunck commented May 18, 2018

Hi,

I've come across the following error when trying to use WriteParameterFile. Below is a toy example that reproduces this problem on my system.

import SimpleITK as sitk
import numpy as np

f = sitk.ElastixImageFilter()

fixedImage = sitk.GetImageFromArray(np.array([[0, 0, 1, 0, 0 ],[0, 0, 1, 0, 0],[1, 1, 1, 1, 1],[0, 0, 1, 0, 0 ],[0, 0, 1, 0, 0] ]))
movingImage = sitk.GetImageFromArray(np.array([[1, 0, 0, 0, 1 ],[0, 1, 0, 1, 0],[0, 0, 1, 0, 0],[0, 1, 0, 1, 0 ],[1, 0, 0, 0, 1] ]))

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(fixedImage)
elastixImageFilter.SetMovingImage(movingImage)
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("rigid"))
elastixImageFilter.Execute()

transformParameterMap = elastixImageFilter.GetTransformParameterMap()

elastixImageFilter.WriteParameterFile( transformParameterMap, "test_transform.txt" )

Here is the error that I get:

Traceback (most recent call last):
File "example.py", line 17, in
elastixImageFilter.WriteParameterFile( transformParameterMap, "test_transform.txt" )
File "/usr/local/lib/python3.6/dist-packages/SimpleITK-1.0.1rc1.dev345+g9dfa8-py3.6-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 10127, in WriteParameterFile
return _SimpleITK.ElastixImageFilter_WriteParameterFile(self, parameterMap, filename)
TypeError: in method 'ElastixImageFilter_WriteParameterFile', argument 2 of type 'std::map< std::string,std::vector< std::string,std::allocator< std::string > >,std::less< std::string >,std::allocator< std::pair< std::string const,std::vector< std::string,std::allocator< std::string > > > > > const'

Not sure if it's relevant, but I'm using Ubuntu 17.10 and SWIG 3.0.

@tfunck
Copy link
Author

tfunck commented May 18, 2018

I found my mistake. The argument that is causing the error is not the output filename for WriteParameterFile, but the parameter map itself. It didn't occur to me that WriteParameter also passes "self" as an argument and therefore that "argument 2" refers to the "parameterMap" and not the "filename" argument.

In the toy example I posted above, the solution is simply to use the first element of the structure returned by GetTransformParameterMap:

transformParameterMap = elastixImageFilter.GetTransformParameterMap()[0]

Apologies if this was something obvious, but it wasn't to me and so maybe this information will be useful to someone else in the future.

@tfunck tfunck closed this as completed May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant