GDCM python DICOM解压
GDCM python DICOM decompression
我执行了这个python script。行中发生错误
t = gdcm.Orientation.GetType(dircos)
错误信息为:
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.
我查了 classes reference。它说
Input is an array of 6 double
变量dircos
正好是一个有6个元素的列表,
>>> dircos
Out[11]: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
不知道为什么会出错
我查看了源代码,发现它实际上是在检查 tuple
。该消息具有误导性。
// 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;
}
= &temp[0];
} else {
PyErr_SetString(PyExc_TypeError,"expected a list.");
return NULL;
}
}
您需要传递一个元组:
>>> import gdcm
>>> dircos = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
>>> gdcm.Orientation.GetType(tuple(dircos))
1
我执行了这个python script。行中发生错误
t = gdcm.Orientation.GetType(dircos)
错误信息为:
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.
我查了 classes reference。它说
Input is an array of 6 double
变量dircos
正好是一个有6个元素的列表,
>>> dircos
Out[11]: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
不知道为什么会出错
我查看了源代码,发现它实际上是在检查 tuple
。该消息具有误导性。
// 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;
}
= &temp[0];
} else {
PyErr_SetString(PyExc_TypeError,"expected a list.");
return NULL;
}
}
您需要传递一个元组:
>>> import gdcm
>>> dircos = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
>>> gdcm.Orientation.GetType(tuple(dircos))
1