如何在使用SimpleTk保存DICOM文件时保留UID?

2024-09-30 05:33:12 发布

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

我正在尝试使用SimpleTk读取一个DICOM文件并将其保存到其他地方。我注意到Series Instance UID的变化与我显式设置它的事实无关

如何保存原始UID

from pathlib import Path
import SimpleITK as sitk

dicom_path = '......'
p = Path(dicom_path)

reader = sitk.ImageFileReader()
reader.SetFileName(str(p))
reader.LoadPrivateTagsOn()

image = reader.Execute()
print('Series Instance UID', image.GetMetaData('0020|000e'))
print('SOP Instance UID', image.GetMetaData('0008|0018'))
image.SetMetaData('0020|000e', image.GetMetaData('0020|000e'))

writer = sitk.ImageFileWriter()
writer.SetFileName(out_folder+case+p.name)
writer.SetUseCompression(False)
writer.Execute(image)

reader = sitk.ImageFileReader()
reader.SetFileName(out_folder+case+p.name)
reader.LoadPrivateTagsOn()

image = reader.Execute()
print('Series Instance UID', image.GetMetaData('0020|000e'))
print('SOP Instance UID', image.GetMetaData('0008|0018'))

为系列UID提供两个不同的字符串。但SOP UID保持不变:

Series Instance UID 1.3.12.2.1107.5.1.4.74141.30000017013107011409700014483
SOP Instance UID 1.3.12.2.1107.5.1.4.74141.30000017013107011409700014570

Series Instance UID 1.2.826.0.1.3680043.2.1125.1.65790274925978549485969544082687134
SOP Instance UID 1.3.12.2.1107.5.1.4.74141.30000017013107011409700014570

Tags: pathinstanceimageimportexecuteuidreaderdicom
1条回答
网友
1楼 · 发布于 2024-09-30 05:33:12

虽然我从未使用过工具箱,但工具箱的行为很奇怪。如果像素数据被修改,一些属性应该被改变;在这种情况下,SOP实例UID是最重要的

但是,在您的情况下,像素数据不会被修改。而且,只修改了Series实例UID;SOP实例UID保持不变

无论如何,工具箱提供了一种在编写DICOM数据集时保留UID的方法。详情请参阅^{}成员

Self& itk::simple::ImageFileWriter::KeepOriginalImageUIDOn (void)
Use the original study/series/frame of reference.

These methods Set/Get/Toggle the KeepOriginalImageUID flag which get's passed to image file's itk::ImageIO object. This is relevant only for the DICOM file format, configuring the writer to use the information in the image's meta-data dictionary or to create new study/series/frame of reference values.

Definition at line 134 of file sitkImageFileWriter.h.

这将指示toolkit在编写数据集时保留原始UID

相关问题 更多 >

    热门问题