在Python中将DICOM结构轮廓作为数组获取

时间:2017-10-10 12:26:20

标签: python arrays dicom pydicom

因此,如果我有一个图像(CT,MRI等)或甚至放射治疗的剂量,我可以通过以下方式将剂量或图像值拉出来:

import dicom

ds = dicom.read_file("dicom_file.dcm")

print ds.pixel_array

这非常简单,让我能够按照自己的意愿操纵图像/剂量。但是,通常您还有一个结构文件,其中包含不同的轮廓结构,您可以在图像查看器中查看这些结构或类似的结构。再次,非常简单。

我的问题是我也希望这些单独的结构也是一个数组。如果我运行相同的代码,我只需TypeError: No pixel data found in this dataset.

我猜测结构DICOM文件不像剂量/图像DICOM文件那样“制作”。

那么我找不到一个解决方案吗?我还查看了dicompyler_core包,但从我所看到的,没有任何方法可以“只是”将不同的结构输出到数组中。

1 个答案:

答案 0 :(得分:3)

这是一个交互式会话,使用pydicom附带的rtstruct.dcm文件说明数据布局:

>>> import dicom
>>> ds = dicom.read_file("rtstruct.dcm", force=True)
>>> ds.dir("contour")
['ROIContourSequence']
>>> ctrs = ds.ROIContourSequence
>>> ctrs[0]
(3006, 002a) ROI Display Color                   IS: ['220', '160', '120']
(3006, 0040)  Contour Sequence   3 item(s) ----
   (3006, 0042) Contour Geometric Type              CS: 'CLOSED_PLANAR'
   (3006, 0046) Number of Contour Points            IS: '5'
   (3006, 0048) Contour Number                      IS: '1'
   (3006, 0050) Contour Data                        DS: ['-200.0', '150.0', '-20
0.0', '-200.0', '-150.0', '-200.0', '200.0', '-150.0', '-200.0', '200.0', '150.0
', '-200.0', '-200.0', '150.0', '-200.0']
   ---------
   (3006, 0042) Contour Geometric Type              CS: 'CLOSED_PLANAR'
   (3006, 0046) Number of Contour Points            IS: '6'
   (3006, 0048) Contour Number                      IS: '2'
   (3006, 0050) Contour Data                        DS: ['200.0', '-0.0', '-190.
0', '200.0', '-150.0', '-190.0', '-200.0', '-150.0', '-190.0', '-200.0', '150.0'
, '-190.0', '200.0', '150.0', '-190.0', '200.0', '-0.0', '-190.0']
   ---------
   (3006, 0042) Contour Geometric Type              CS: 'CLOSED_PLANAR'
   (3006, 0046) Number of Contour Points            IS: '6'
   (3006, 0048) Contour Number                      IS: '3'
   (3006, 0050) Contour Data                        DS: ['200.0', '-0.0', '-180.
0', '200.0', '-150.0', '-180.0', '-200.0', '-150.0', '-180.0', '-200.0', '150.0'
, '-180.0', '200.0', '150.0', '-180.0', '200.0', '-0.0', '-180.0']
   ---------
(3006, 0084) Referenced ROI Number               IS: '1'

将数据存储(在这种情况下,通常)作为每个平面的一组坐标。要获取一个轮廓的数据,对于一个平面,您可以使用

>>> ctrs[0].ContourSequence[0].ContourData
['-200.0', '150.0', '-200.0', '-200.0', '-150.0', '-200.0', '200.0', '-150.0', '
-200.0', '200.0', '150.0', '-200.0', '-200.0', '150.0', '-200.0']

这些是(x,y,z)坐标的三元组一个接一个。

您可以在StructureSetROISequence序列中找到有关每个轮廓(名称等)的更多信息,参考参考ROI编号给出的索引。

您可以通过循环ContourSequence中每个特定轮廓的数据集并将它们一起附加到一个数组中来获得所有这些数组的完整数组。