2

我有很多 DICOM 数据集,其中有一个私有标签,其中包含我不想保留在标题中的信息。这个标签的值会随着每个数据集的变化而变化,所以我不知道这个值。这是我想要更新或删除的私人创建者和私人标签的示例。

0033,0010  ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016  ---: Dummy^Data^G^

我希望能够完全删除0033,1016或使用新值更新它。我尝试过的一切要么什么都不做,要么会添加另一个0033,1016标签,创建两个0033,1016标签。一个是原件,一个是我尝试更新原件时添加的。

0033,0010  ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016  ---: Dummy^Data^G^
0033,1016  ---: FOO

如果我再次运行代码,我可以更新0033,1016具有 value的标签FOO,但我永远无法更改0033,1016带有 value 的标签Dummy^Data^G^

以下是我的代码:

string main_path = @"C:\Users\pthalken\Desktop\foo";

DirectoryInfo foo = new DirectoryInfo(main_path);
FileInfo[] dicomFiles = foo.GetFiles();

foreach(FileInfo files in dicomFiles)
{
    DicomFile openedDicom = DicomFile.Open(files.FullName, FileReadOption.ReadAll);

    //getting the private tag that I want to change or remove
    var remove = DicomTag.Parse("0033,1016");
    var test = DicomTag.Parse("0010,0010");

    //this method will work for public tags as expected, but with private tags it will juist add another tag
    //it will not update the orignial tag. If ran again it will change the recently inputted tag but still not touch the original
    openedDicom.Dataset.AddOrUpdate(remove, "FOO");

    //Does not update original tag, will add another 0033,1016 tag with value HOT
    openedDicom.Dataset.AddOrUpdate(new DicomCodeString(openedDicom.Dataset.GetPrivateTag(new DicomTag(0x0033, 0x1016)), "HOT"));

    //Does not update original tag, will add another 0033,1016 tag with value HOT CHEETO
    openedDicom.Dataset.AddOrUpdate(new DicomCodeString(openedDicom.Dataset.GetPrivateTag(remove), "HOT CHEETO"));

    //does not remove the orignial tag
    openedDicom.Dataset.Remove(remove);
    openedDicom.Save(files.FullName);
}
4

2 回答 2

3

使用 fo-DICOM 4.0.7 版,以下代码可以正确地从数据集中删除和更新私有标签:

string dirPath = @"C:\.....";
string filePath = Path.Combine(dirPath, "Test.dcm");
DicomFile openedDicom = DicomFile.Open(filePath, FileReadOption.ReadAll);

var remove = DicomTag.Parse("0019,0010");
openedDicom.Dataset.Remove(remove);
openedDicom.Save(Path.Combine(dirPath, "Removed.dcm"));

var edit = DicomTag.Parse("0043,0010");
openedDicom.Dataset.AddOrUpdate(edit, "EDITED");
openedDicom.Save(Path.Combine(dirPath, "Edited.dcm"));

我没有您提到的私有标签的数据集;我使用的标签不同,但这无关紧要。

但是有一个问题。如果VR私有标签是[UN - Unknown],则两者都Remove不起作用AddOrUpdate。这似乎与未知值表示有关。

我试图读取元素的值,VR如下UN所示:

var read = DicomTag.Parse("0019,1002");
string value = openedDicom.Dataset.GetString(read);

失败但GetString有以下异常:

标签: (0019,1002) 在数据集中找不到

在 Visual Studio 中,如果您使用 快速openedDicom.Dataset查看来查找元素UN VR,您会观察到奇怪的结果。

似乎 fo-DICOM 在阅读UN VR.


你有问题说:

我尝试过的一切要么什么都不做,要么会添加另一个 0033,1016 标签,创建两个 0033,1016 标签。

它创建新标签,因为它无法找到现有标签。检查VR新创建的标签;我想这将是其他的东西UN。这就是为什么您可以编辑新创建的标签,但不能编辑原始标签。

于 2020-12-03T07:10:28.563 回答
0

我设法访问了私有 DICOM 标签。但我注意到不仅需要指定组和元素编号,还需要指定私有创建者。此外,我使用了定制的私人词典。

  1. 我在私有字典中指定了私有标签。
    在这里指定值表示是有意义的。关键字是可选的。
    <dictionary creator="UIS_IMAGE_PRESENTATION">
        <tag group="0019" element="xx10" vr="SQ" vm="1" keyword="TechnicalPresentationState">Technical Presentation State</tag>
        <tag group="0019" element="xx20" vr="CS" vm="1" keyword="UISExportMode">UIS Export Mode</tag>
        <tag group="0019" element="xx41" vr="CS" vm="1" keyword="PreHorizontalFlip">Pre Horizontal Flip</tag>
        <tag group="0019" element="xx42" vr="DS" vm="1" keyword="PreRotationAngle">Pre Rotation Angle</tag>
        <tag group="0019" element="xx43" vr="CS" vm="1" keyword="CPStepHorizontalFlip">CP Step Horizontal Flip</tag>
        <tag group="0019" element="xx44" vr="CS" vm="1" keyword="CPStepVerticalFlip">CP Step Vertical Flip</tag>
        <tag group="0019" element="xx45" vr="DS" vm="1" keyword="CPStepRotationAngle">CP Step Rotation Angle</tag>
    </dictionary>
  1. 为了访问标签,我创建了一个新实例DicomTag
private DicomTag Dicom_Private_UisImagePresentation_PreHorizontalFlip { get; set; }
public string Dicom_Private_UisImagePresentation_PreHorizontalFlip_value { get; set; }
...
Dicom_Private_UisImagePresentation_PreHorizontalFlip = new DicomTag(0x0019, 0x1041, "UIS_IMAGE_PRESENTATION");
  1. 为了获得价值,我使用了该GetSingleValue<string>方法。
Dicom_Private_UisImagePresentation_PreHorizontalFlip_value = DicomFile.Dataset.GetSingleValue<string>(Dicom_Private_UisImagePresentation_PreHorizontalFlip);

处理 VR="UN"有点棘手。因此,您需要知道标签中放入了什么。我建议检查一下,是否有更好的 VR 可以用来代替“UN”。

于 2022-01-02T13:35:10.667 回答