问题描述
因此,如果我有图像(CT,MRI等)甚至是放射治疗的剂量,我可以通过以下方式将剂量或图像值提取到阵列中:
So if I have an image (CT, MRI, etc.) or even a dose from radiation therapy I can pull out the dose or image values into an array through:
import dicom
ds = dicom.read_file("dicom_file.dcm")
print ds.pixel_array
这非常简单,使我能够根据需要操纵图像/剂量.但是,通常您还拥有一个结构文件,其中包含不同的轮廓结构,然后您可以在图像查看器中看到类似的东西.再次,非常简单.
This is pretty straightforward, and gives me the ability to manipulate images/doses as I want. However, often you also have a structure file that includes different contoured structures that you can then see in an image viewer or something like that. Again, pretty straightforward.
我的问题是,我也希望这些单独的结构也可以作为数组.如果我运行相同的代码,我只会得到TypeError: No pixel data found in this dataset.
My problem is that I would also like these individual structures as an array as well. And if I run the same code I just get TypeError: No pixel data found in this dataset.
我猜想结构DICOM文件的制作方式与剂量/图像DICOM文件的制作方式不同.
I'm guessing that structure DICOM files are not "made" the same way as dose/images DICOM files.
那么有没有我无法找到的解决方案?我还查看了dicompyler_core
程序包,但是从我看到的结果来看,没有任何方法可以仅仅"将不同的结构分解为数组.
So is there a solution to this that I haven't been able to find ? I have also looked at the dicompyler_core
package, but from what I could see there wasn't any way to "just" get out the different structures into arrays.
推荐答案
以下是一个交互式会话,它使用pydicom随附的rtstruct.dcm文件说明了数据布局:
Here is an interactive session illustrating the data layout using the rtstruct.dcm file included with 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'
数据(在这种情况下,通常如此)存储为每个平面的一组坐标.要获取一个轮廓,一个平面的数据,您可以使用
The data is stored (in this case, as is usual) as a set of coordinates for each plane. To get the data for one contour, for one plane, you could use
>>> 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)坐标一个接一个的三胞胎.
These are triplets of (x, y, z) coordinates one after the other.
您可以在StructureSetROISequence
序列中找到有关每个轮廓(名称等)的更多信息,以获取由参考的ROI编号"给出的索引.
You can find out more information about each contour (name, etc) in the StructureSetROISequence
sequence, for the index given by Referenced ROI Number.
通过遍历ContourSequence中特定轮廓的每个数据集并将它们附加到一个数组中,您可以获得所有这些的完整数组.
You could get a complete array for all of these by looping through each dataset in the ContourSequence for that particular contour and appending them together into one array.
这篇关于在Python中获取DICOM结构轮廓作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!