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

calling sitk function with int argument does not work with Python 3 #204

Closed
haarburger opened this issue Feb 17, 2017 · 10 comments
Closed

Comments

@haarburger
Copy link
Contributor

haarburger commented Feb 17, 2017

@jcfr When using Python 3.5, resampling as implemented in imageoperations.py#L187 does not work.

sitk.ResampleImageFilter accepts uint32_t arguments. In Python 2.7 this works fine with passing np.int. However, in Python 3 this is not working anymore.

Example:

rif = sitk.ResampleImageFilter()
rif.SetSize(np.array([1, 2, 3], dtype='int'))

TypeError: in method 'ResampleImageFilter_SetSize', argument 2 of type 'std::vector< uint32_t,std::allocator< uint32_t > > const &'

Which numpy type whould result in uint32_t for both python 2 and 3? With np.uint32 I get the same error.

Converting the array to python int with arr = [int(x) for x in arr] resolves the issue but is ugly...

@JoostJM
Copy link
Collaborator

JoostJM commented Feb 17, 2017

@haarburger, thanks for the heads up! This conversion was giving us trouble before (and fixed it by casting to 'int', but apparently doesn't work for python 3). We'll look into it to make it python 3 compatible. If you find a solution in the meantime, we'd welcome your contribution.

@haarburger
Copy link
Contributor Author

np.array([1, 2, 3], dtype='int').tolist() does the trick. I'll create a PR shortly.

@jcfr
Copy link
Collaborator

jcfr commented Feb 17, 2017

rif = sitk.ResampleImageFilter()
rif.SetSize(np.array([1, 2, 3], dtype='int'))
TypeError: in method 'ResampleImageFilter_SetSize', argument 2 of type 'std::vector< uint32_t,std::allocator< uint32_t > > const &'

np.array([1, 2, 3], dtype='int').tolist() does the trick. I'll create a PR shortly.

@blowekamp Would it make sense to improve the wrapping layer to directly understand numpy array as parameter ?

@blowekamp
Copy link

blowekamp commented Feb 17, 2017 via email

@haarburger
Copy link
Contributor Author

@blowekamp Actually, np.array([1, 2, 3], dtype='uint32') was the first thing I tried, but it doesn't work.

@JoostJM
Copy link
Collaborator

JoostJM commented Feb 18, 2017

@haarburger, did you also try 'uint'?

@haarburger
Copy link
Contributor Author

Yes, doesn't work either.

@blowekamp
Copy link

I will have to look into the further. Can you please create a SimpleITK Issue, and include the SimpleITK version, OS, Python Distribute, etc.. where the problem has occurred?

Have you checked if SimpleITK 1.0rc1 has the same issue?

@haarburger
Copy link
Contributor Author

haarburger commented Feb 19, 2017

@blowekamp the problem also occurs with 1.0rc1.

@JoostJM
Copy link
Collaborator

JoostJM commented Feb 21, 2017

Resolved by #205

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

4 participants