我正在尝试使用pydicom获取给定DICOM实例的所有属性(标记)的列表。
该列表应该包括属性键/id、它的vr、值以及相应的名称。
例如:
Tag: (2,0)
VR: UL
Name: File Meta Information Group Length
Value: 246我想获得一些关于如何获得这些信息的指导,因为我在pydicom文档中找不到任何有用的东西。
我的代码如下:
import pydicom
from io import BytesIO
dicom_data = await client.download_dicom_file(image_id)
data = pydicom.dcmread(BytesIO(dicom_data))发布于 2021-07-10 01:27:24
要获得所有标签,只需迭代数据集中的所有元素。文档中的Here就是这样做的一个例子。它可以归结为:
from pydicom import dcmread
ds = dcmread(file_name)
for element in ds:
print(element)该示例还展示了如何处理序列(通过递归迭代序列项)。下面是一个仅使用元素的字符串表示来处理序列项的简单示例:
def show_dataset(ds, indent):
for elem in ds:
if elem.VR == "SQ":
indent += 4 * " "
for item in elem:
show_dataset(item, indent)
indent = indent[4:]
print(indent + str(elem))
def print_dataset(file_name):
ds = dcmread(file_name)
show_dataset(ds, indent="")如果您想打印您自己的数据元素表示,您可以访问元素属性。每个元素都是一个DataElement,其中包含您需要的信息:
>>> from pydicom import dcmread
>>> ds = dcmread("ct_small.dcm") # from the test data
>>> len(ds)
258
>>> element = ds[0x00080008]
>>> element
(0008, 0008) Image Type CS: ['ORIGINAL', 'PRIMARY', 'AXIAL']
>>> type(element)
<class 'pydicom.dataelem.DataElement'>
>>> element.VR
'CS'
>>> element.tag
(0008, 0008)
>>> element.name
'Image Type'
>>> element.value
['ORIGINAL', 'PRIMARY', 'AXIAL']
>>> element.VM
3您可以在Dataset的文档中找到类似的信息,可能在其他示例中也有类似的信息。
请注意,还有一个显示DICOM文件内容的command line interface。
https://stackoverflow.com/questions/68319272
复制相似问题