首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自Python的GDCM ImageRegionReader

来自Python的GDCM ImageRegionReader
EN

Stack Overflow用户
提问于 2017-11-30 06:22:22
回答 0查看 174关注 0票数 0

我正在尝试使用GDCM从dicom文件中只读取一个切片。数据是多片dicom。

代码语言:javascript
复制
r = gdcm.ImageRegionReader()
r.SetFileName( 'test.dcm' )
r.ReadInformation()

image = r.GetImage()
dimensions = image.GetDimensions()
pixelformat = image.GetPixelFormat()
pixelsize = pixelformat.GetPixelSize()

bytes_per_slice = dimensions[0] * dimensions[1] * pixelsize

box = gdcm.BoxRegion()
box.SetDomain(0, dimensions[0] - 1, 0, dimensions[1] - 1, 1, 1)

r.SetRegion(box)

这一切都可以工作,但是我如何读取像素呢?

代码语言:javascript
复制
nptypes = {gdcm.PixelFormat.UINT8  :numpy.int8,
            gdcm.PixelFormat.INT8   :numpy.uint8,
            gdcm.PixelFormat.UINT16 :numpy.uint16,
            gdcm.PixelFormat.INT16  :numpy.int16,
            gdcm.PixelFormat.UINT32 :numpy.uint32,
            gdcm.PixelFormat.INT32  :numpy.int32,
            gdcm.PixelFormat.FLOAT32:numpy.float32,
            gdcm.PixelFormat.FLOAT64:numpy.float64 }

arr = np.array(bytes_per_slice, dtype=pixelformat.GetScalarType())
# also tried np.uint8 as dtype
buffer = np.getbuffer(arr)


#
# now this fails
#
r.ReadIntoBuffer(buffer, bytes_per_slice)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-95-a8022420e1c1> in <module>()
----> 1 r.ReadIntoBuffer(buffer, bytes_per_slice)

lib/python2.7/site-packages/gdcmswig.pyc in ReadIntoBuffer(self, inreadbuffer, buflen)
  20678         Read into buffer: false upon error
  20679         """
> 20680         return _gdcmswig.ImageRegionReader_ReadIntoBuffer(self, inreadbuffer, buflen)
  20681 
  20682 ImageRegionReader_swigregister = _gdcmswig.ImageRegionReader_swigregister

TypeError: in method 'ImageRegionReader_ReadIntoBuffer', argument 2 of type 'char *'

如何传递numpy缓冲区?我尝试了一些ctype的东西,但它们都不起作用。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47562830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档