我需要使用GDCM将DICOM图像转换为PNG格式。当this example起作用时,它似乎没有考虑到{a3},因此我得到了一个反转/非反转图像的混合。虽然我熟悉C++和Python,但我不能很好地理解包装器中的黑魔力。文档是纯C++编写的,我需要一些帮助来连接这些点。在
主要任务
转换示例中的以下部分:
def gdcm_to_numpy(image):
....
gdcm_array = image.GetBuffer()
result = numpy.frombuffer(gdcm_array, dtype=dtype)
....
像这样的事情:
^{pr2}$现在给出错误:
NotImplementedError: Wrong number or type of arguments for overloaded function 'LookupTable_Decode'.
Possible C/C++ prototypes are:
gdcm::LookupTable::Decode(std::istream &,std::ostream &) const
gdcm::LookupTable::Decode(char *,size_t,char const *,size_t) const
从GetBuffer定义来看,我猜第一个参数是赋值变量bool GetBuffer(char *buffer) const;
。我想后一个四元版本才是我的目标。不幸的是,我不知道size_t
参数应该是什么。我试过了
gdcm_in_size = sys.getsizeof(gdcm_array)
gdcm_out_size = sys.getsizeof(gdcm_array)*3
gdcm_decoded = lut.Decode(gdcm_out_size, gdcm_array, gdcm_in_size)
还有
gdcm_in_size = ctypes.sizeof(gdcm_array)
gdcm_out_size = ctypes.sizeof(gdcm_array)*3
gdcm_decoded = lut.Decode(gdcm_out_size, gdcm_array, gdcm_in_size)
但是没有成功。在
ImageApplyLookupTable
更新-测试...
lutfilt = gdcm.ImageApplyLookupTable();
lutfilt.SetInput( image );
if (not lutfilt.Apply()):
print("Failed to apply LUT")
gdcm_decoded = lutfilt.GetOutputAsPixmap()\
.GetBuffer()
dtype = get_numpy_array_type(pf)
result = numpy.frombuffer(gdcm_decoded, dtype=dtype)
...
不幸的是,我得到了“未能应用LUT”打印,图像仍然颠倒。如下图所示,ImageJ表明它有一个反转的LUT。在
作为一个简单的解决方案,我将首先应用LUT。在这种情况下,您需要使用ImageApplyLookupTable。它在内部调用gdcm::LookupTableAPI。有关example,请参阅。在
当然,正确的解决方案是传递DICOM LUT并将其转换为PNG LUT。在
更新:现在你已经发布了截图。我理解你那边的情况。您不是在尝试应用DICOM查找表,而是尝试更改两个不同的光度转换DICOM数据集的渲染,即单色1与单色2。在
在这种情况下,您可以使用软件实现通过使用:gdcm.ImageChangePhotometricInterpretation来更改它。从技术上讲,这种类型的渲染最好使用图形卡来完成(但这是另一回事)。在
相关问题 更多 >
编程相关推荐