【问题标题】:How can I remove or update a private tag using fo-DICOM?如何使用 fo-DICOM 删除或更新私有标签?
【发布时间】:2020-12-02 22:10:00
【问题描述】:

我有很多 DICOM 数据集,其中有一个私有标签,其中包含我不想保留在标题中的信息。此标签的值随每个数据集而变化,因此我不知道该值。以下是我想要更新或删除的 PRIVATE CREATOR 和 Private Tag 的示例。

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

如果我再次运行代码,我可以更新值为FOO0033,1016,但我永远无法将0033,1016 标记为值为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);
}

【问题讨论】:

    标签: c# dicom fo-dicom


    【解决方案1】:

    对于 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],则RemoveAddOrUpdate 都不起作用。这似乎与未知值表示有关。

    我尝试读取VRUN 的元素的值,如下所示:

    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。这就是为什么,您可以编辑新创建的标签,但不能编辑原始标签。

    【讨论】:

    • 我查看了我要删除或更新的标签的 VR,它们的 VR 为 PN 或 AE。了解 VR 会帮助我删除或更新这些私人标签吗? fo-dicom 不可能做到这一点吗?另外我应该提到我正在使用 fo-dicom 4.0.7
    • @franklinCat:正如我在回答中提到的那样,使用 fo-DICOM 很有可能。我自己尝试过,它正在工作。我面临的唯一问题是与您遇到的类似行为,但仅限于 VR UN Private Tags。其他一切都很好。
    • 您可以尝试使用样本以外的其他数据集吗?你可以在互联网上找到很多。
    • @franklinCat:还有一个建议。万一您的数据集使用隐式 VR 编码,您可以尝试将数据集的传输语法更改为“隐式 VR .....”以外的其他内容吗?可能明确指定 VR 可能会有所帮助。胡思乱想……
    【解决方案2】:

    我设法访问了私有 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&lt;string&gt; 方法。
    Dicom_Private_UisImagePresentation_PreHorizontalFlip_value = DicomFile.Dataset.GetSingleValue<string>(Dicom_Private_UisImagePresentation_PreHorizontalFlip);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多