Den*_*ang 8 python arrays dicom pydicom
因此,如果我有一个图像(CT,MRI等)或甚至放射治疗的剂量,我可以通过以下方式将剂量或图像值拉出到阵列中:
import dicom
ds = dicom.read_file("dicom_file.dcm")
print ds.pixel_array
Run Code Online (Sandbox Code Playgroud)
这非常简单,让我能够按照自己的意愿操纵图像/剂量.但是,通常您还有一个结构文件,其中包含不同的轮廓结构,您可以在图像查看器中查看这些结构或类似的结构.再次,非常简单.
我的问题是我也希望这些单独的结构也是一个数组.如果我运行相同的代码我就会得到TypeError: No pixel data found in this dataset.
我猜测结构DICOM文件不像剂量/图像DICOM文件那样"制作".
那么有一个我无法找到的解决方案吗?我也看了一下这个dicompyler_core软件包,但从我看到的情况来看,没有任何办法可以"只是"将不同的结构输出到数组中.
这是使用 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'
Run Code Online (Sandbox Code Playgroud)
数据存储(在这种情况下,像往常一样)作为每个平面的一组坐标。要获取一个轮廓的数据,对于一个平面,您可以使用
>>> 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']
Run Code Online (Sandbox Code Playgroud)
这些是一个接一个的 (x, y, z) 坐标的三元组。
您可以找到有关StructureSetROISequence序列中每个轮廓(名称等)的更多信息,以参考 ROI 编号给出的索引。
通过循环遍历 ContourSequence 中特定轮廓的每个数据集并将它们一起附加到一个数组中,您可以获得所有这些的完整数组。