簡體   English   中英

如何使用 fo-DICOM 刪除或更新私有標簽?

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

我有很多 DICOM 數據集,其中有一個私有標簽,其中包含我不想保留在 header 中的信息。每個數據集的這個標簽的值都會發生變化,所以我不知道該值。 這是我要更新或刪除的 PRIVATE CREATOR 和私人標簽的示例。

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 ,但我永遠無法更改值為Dummy^Data^G^0033,1016標簽。

以下是我的代碼:

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

對於 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以外的其他組織。 這就是為什么您可以編輯新創建的標簽但不能編輯原始標簽的原因。

我設法訪問了私人 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”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM