我有很多 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);
}