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. Here is an example of the PRIVATE CREATOR and the Private Tag I want to be updated or removed.
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. Everything I have tried either does nothing or will add another 0033,1016
tag, creating two 0033,1016
tag. 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^
.
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:
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]
, bothRemove
andAddOrUpdate
does not work. It appears that this has something to do with unknown value representation.I tried to read the value of element whose
VR
isUN
as below:The
GetString
failed with following exception:In Visual Studio, if you Quick Watch the
openedDicom.Dataset
to find the elements withUN
VR
, you will observe strange results.It seems that fo-DICOM have an issues reading elements with
UN
VR
.You said in question:
It creates new tag because it could not locate existing tag. Check the
VR
of the newly created tag; I guess it will be something other thanUN
. That is why, you are able to edit that newly created tag but not the original one.