在Python中以数组形式获取DICOM结构轮廓

2024-05-16 17:44:15 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,如果我有一个图像(CT、MRI等)甚至是放射治疗的剂量,我可以通过以下方式将剂量或图像值提取到一个数组中:

import dicom

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

print ds.pixel_array

这很简单,让我可以随心所欲地操作图像/剂量。然而,通常你也有一个包含不同轮廓结构的结构文件,你可以在图像查看器或类似的东西中看到。再说一次,非常直截了当。在

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

我猜结构DICOM文件并不像dose/images DICOM文件那样“生成”。在

那么,有没有一个我还没有找到的解决办法呢?我还研究了dicompyler_core包,但是从我所看到的情况来看,没有任何方法可以“仅仅”将不同的结构转换成数组。在


Tags: 文件图像import方式ds数组结构file
1条回答
网友
1楼 · 发布于 2024-05-16 17:44:15

下面是一个交互式会话,演示了使用rtstruct.dcm公司pydicom附带的文件:

>>> 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'

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

^{pr2}$

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

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

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

相关问题 更多 >