简体   繁体   English

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

[英]How can I remove or update a private tag using fo-DICOM?

I have a lot of DICOM data sets that have a private tag in them that contain information that I do not want to keep in the header. The value for this tag changes for each dataset, so I do not know the value.我有很多 DICOM 数据集,其中有一个私有标签,其中包含我不想保留在 header 中的信息。每个数据集的这个标签的值都会发生变化,所以我不知道该值。 Here is an example of the PRIVATE CREATOR and the Private Tag I want to be updated or removed.这是我要更新或删除的 PRIVATE CREATOR 和私人标签的示例。

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

I want to be able to either completely remove 0033,1016 or update it with a new value.我希望能够完全删除0033,1016或使用新值更新它。 Everything I have tried either does nothing or will add another 0033,1016 tag, creating two 0033,1016 tag.我尝试过的一切要么什么都不做,要么会添加另一个0033,1016标签,从而创建两个0033,1016标签。 One is the original and one that was added when I tried to update the original.一个是原来的,一个是我尝试更新原件时添加的。

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

If I run the code again, I can update the 0033,1016 that has the value FOO , but I can never change the 0033,1016 tag with the value Dummy^Data^G^ .如果我再次运行代码,我可以更新值为FOO0033,1016 ,但我永远无法更改值为Dummy^Data^G^0033,1016标签。

Following is my code:以下是我的代码:

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);
}

With version 4.0.7 of fo-DICOM, following code does properly remove and update the private tag from the dataset:对于 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"));

I do not have dataset with the private tags you mentioned in question;我没有您提到的带有私人标签的数据集; the tags I used are different but that should not matter.我使用的标签不同,但这无关紧要。

But, there is a catch.但是有一个问题。 If VR of the private tag is [UN - Unknown] , both Remove and AddOrUpdate does not work.如果私有标签的VR[UN - Unknown]RemoveAddOrUpdate都不起作用。 It appears that this has something to do with unknown value representation.看来这与未知值表示有关。

I tried to read the value of element whose VR is UN as below:我尝试读取VRUN的元素的值,如下所示:

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

The GetString failed with following exception: GetString失败,出现以下异常:

Tag: (0019,1002) not found in dataset标签:(0019,1002) 在数据集中找不到

In Visual Studio, if you Quick Watch the openedDicom.Dataset to find the elements with UN VR , you will observe strange results.在 Visual Studio 中,如果您快速观看打开的openedDicom.Dataset以使用UN VR查找元素,您将观察到奇怪的结果。

It seems that fo-DICOM have an issues reading elements with UN VR . fo-DICOM 似乎在读取UN VR元素时遇到问题。


You said in question:你有问题说:

Everything I have tried either does nothing or will add another 0033,1016 tag, creating two 0033,1016 tag.我尝试过的一切要么什么都不做,要么会添加另一个 0033,1016 标签,从而创建两个 0033,1016 标签。

It creates new tag because it could not locate existing tag.它会创建新标签,因为它无法找到现有标签。 Check the VR of the newly created tag;查看新建标签的VR I guess it will be something other than UN .我想这将是UN以外的其他组织。 That is why, you are able to edit that newly created tag but not the original one.这就是为什么您可以编辑新创建的标签但不能编辑原始标签的原因。

I managed to access private DICOM tags.我设法访问了私人 DICOM 标签。 But I noticed that it is necessary to not only specify the group and element number but also the private creator.但是我注意到,不仅需要指定组和元素号,还需要指定私有创建者。 Additionally I used a customized private dictionary.此外,我还使用了定制的私人词典。

  1. I specified the private tags in the private dictionary.我在私有字典中指定了私有标签。
    Here it makes sense to specify the value representation.在这里指定值表示是有意义的。 The keyword is optional.关键字是可选的。
    <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. To acces the tags I created a new instance of DicomTag为了访问标签,我创建了一个新的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. To get the value I used the GetSingleValue<string> method.为了获取值,我使用了GetSingleValue<string>方法。
Dicom_Private_UisImagePresentation_PreHorizontalFlip_value = DicomFile.Dataset.GetSingleValue<string>(Dicom_Private_UisImagePresentation_PreHorizontalFlip);

To handle VR="UN" is a little tricky.处理VR="UN"有点棘手。 Therefore you need to know what was put into the tag.因此,您需要知道标签中放入了什么。 I recommend to check, if there is a better VR which could be used instead of "UN".我建议检查是否有更好的 VR 可以用来代替“UN”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM