[英]GDCM python DICOM decompression
I executed this python script . 我执行了这个python脚本 。 An error happened in the line
该行发生错误
t = gdcm.Orientation.GetType(dircos)
The error information is: 错误信息是:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2820, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-8-fb43b0929780>", line 1, in <module>
gdcm.Orientation.GetType(dircos)
TypeError: expected a list.
I looked up the classes reference . 我查阅了类参考 。 It says
它说
Input is an array of 6 double
输入是一个6双的数组
The variable dircos
is exactly a list with 6 elements, 变量
dircos
正是一个包含6个元素的列表,
>>> dircos
Out[11]: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
I don't know why it goes wrong. 我不知道为什么会出错。
I checked the source code and found that it actually check for tuple
. 我检查了源代码,发现它实际上检查了
tuple
。 The message is misleading. 该消息具有误导性。
// Grab a 6 element array as a Python 6-tuple
%typemap(in) const double dircos[6] (double temp[6]) { // temp[6] becomes a local variable
int i;
if (PyTuple_Check($input) /*|| PyList_Check($input)*/) {
if (!PyArg_ParseTuple($input,"dddddd",temp,temp+1,temp+2,temp+3,temp+4,temp+5)) {
PyErr_SetString(PyExc_TypeError,"list must have 6 elements");
return NULL;
}
$1 = &temp[0];
} else {
PyErr_SetString(PyExc_TypeError,"expected a list.");
return NULL;
}
}
You need to pass a tuple: 你需要传递一个元组:
>>> import gdcm
>>> dircos = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
>>> gdcm.Orientation.GetType(tuple(dircos))
1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.