首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用fo-DICOM删除或更新私有标记?

如何使用fo-DICOM删除或更新私有标记?
EN

Stack Overflow用户
提问于 2020-12-02 22:10:00
回答 2查看 1.5K关注 0票数 3

我有很多DICOM数据集,这些数据集中有一个私有标记,其中包含我不希望保存在标头中的信息。此标记的值对每个数据集都有更改,因此我不知道值。下面是一个私有创建者和我想要更新或删除的私有标记的示例。

代码语言:javascript
复制
0033,0010  ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016  ---: Dummy^Data^G^

我希望能够完全删除0033,1016或用新值更新它。我尝试过的所有东西要么什么都不做,要么添加另一个0033,1016标记,创建两个0033,1016标记。一个是原始的,另一个是在我试图更新原始版本时添加的。

代码语言:javascript
复制
0033,0010  ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016  ---: Dummy^Data^G^
0033,1016  ---: FOO

如果我再次运行代码,我可以更新具有值0033,1016FOO,但是我永远不能用值Dummy^Data^G^来更改0033,1016标记。

以下是我的代码:

代码语言:javascript
复制
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);
}
EN

回答 2

Stack Overflow用户

发布于 2020-12-03 07:10:28

使用fo-DICOM的4.0.7版本,下面的代码正确地从dataset中删除和更新私有标记:

代码语言:javascript
复制
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"));

我没有您提到的私有标记的dataset;我使用的标记是不同的,但这不重要。

但是,这里有一个陷阱。如果私有标记的VR[UN - Unknown],则RemoveAddOrUpdate都不能工作。这似乎与未知值表示有关。

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

代码语言:javascript
复制
var read = DicomTag.Parse("0019,1002");
string value = openedDicom.Dataset.GetString(read);

GetString失败,例外情况如下:

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

在Visual中,如果快速观察openedDicom.Dataset以查找带有UN VR的元素,则会观察到奇怪的结果。

在使用UN VR读取元素时,fo-DICOM似乎存在问题。

你说过:

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

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

票数 4
EN

Stack Overflow用户

发布于 2022-01-02 13:35:10

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

  1. I在私有字典中指定了私有标记。

在这里,指定值表示是有意义的。关键字是可选的.

代码语言:javascript
复制
    <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>

访问我创建的DicomTag新实例的标记的

代码语言:javascript
复制
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>方法.

的值。

代码语言:javascript
复制
Dicom_Private_UisImagePresentation_PreHorizontalFlip_value = DicomFile.Dataset.GetSingleValue<string>(Dicom_Private_UisImagePresentation_PreHorizontalFlip);

处理VR="UN"有点棘手。因此,您需要知道标记中包含了什么。我建议检查,是否有一个更好的虚拟现实可以使用而不是“联合国”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65116887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档