Pyradiomics: 使用 int 参数调用 sitk 函数不适用于 Python 3

创建于 2017-02-17  ·  10评论  ·  资料来源: AIM-Harvard/pyradiomics

@jcfr使用 Python 3.5 时,在imageoperations.py#L187中实现的重新采样不起作用。

sitk.ResampleImageFilter接受 uint32_t 参数。 在 Python 2.7 中,通过np.int可以正常工作。 但是,在 Python 3 中,这不再有效。

例子:

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 &'

python 2和3的哪个numpy类型会导致uint32_t? 使用np.uint32我得到同样的错误。

使用arr = [int(x) for x in arr]将数组转换为 python int $ 可以解决问题,但很难看......

最有用的评论

np.array([1, 2, 3], dtype='int').tolist()可以解决问题。 我很快就会创建一个 PR。

所有10条评论

@haarburger ,感谢您的提醒! 这种转换之前给我们带来了麻烦(并通过强制转换为'int'来修复它,但显然不适用于python 3)。 我们将对其进行研究以使其与 python 3 兼容。 如果您在此期间找到解决方案,我们欢迎您的贡献。

np.array([1, 2, 3], dtype='int').tolist()可以解决问题。 我很快就会创建一个 PR。

rif = sitk.ResampleImageFilter()
rif.SetSize(np.array([1, 2, 3], dtype='int'))
TypeError:在“ResampleImageFilter_SetSize”方法中,“std::vector< uint32_t,std::allocator<uint32_t >> const &”类型的参数 2

np.array([1, 2, 3], dtype='int').tolist() 可以解决问题。 我很快就会创建一个 PR。

@blowekamp改进包装层以直接将 numpy 数组理解为参数是否有意义?

我会尝试对 numpy 数组使用无符号整数类型。
np.array([1, 2, 3], dtype='uint32')

Swig 包装层确实理解 numpy 数组。 它不会将 numpy 有符号整数数组隐式转换为无符号数组类型。

2017 年 2 月 17 日下午 5:40,Jean-Christophe Fillion-Robin [email protected]写道:

rif = sitk.ResampleImageFilter()
rif.SetSize(np.array([1, 2, 3], dtype='int'))
TypeError:在“ResampleImageFilter_SetSize”方法中,“std::vector< uint32_t,std::allocator<uint32_t >> const &”类型的参数 2

np.array([1, 2, 3], dtype='int').tolist() 可以解决问题。 我很快就会创建一个 PR。

@blowekamp改进包装层以直接将 numpy 数组理解为参数是否有意义?


你收到这个是因为你被提到了。
直接回复此电子邮件,在 GitHub 上查看它,或将线程静音。

@blowekamp实际上, np.array([1, 2, 3], dtype='uint32')是我尝试的第一件事,但它不起作用。

@haarburger ,你也试过'uint'吗?

是的,也不起作用。

我将不得不进一步研究。 您能否创建一个SimpleITK 问题,并包括 SimpleITK 版本、操作系统、Python 分发等。问题发生在哪里?

你检查过 SimpleITK 1.0rc1 是否有同样的问题吗?

@blowekamp 1.0rc1也会出现问题。

由 #205 解决

此页面是否有帮助?
0 / 5 - 0 等级