Hi everyone,
I have a directory with DICOM slice files from different patients, study dates and sequences. I can loop through them, put them in folders such that there is only one sequence per folder, study date and patient. So far so good.
But as soon as I change some tags to anonymize, the slices are no longer recognized to belong to the same series if loaded e.g. into 3DSlicer or itksnap. They are shown with the same SeriesNumber, but not as to belong to the same volume.
The only difference between only copying the slices to different folders and the second option is that I change some tags and save instead of copy slices.
I am working with SimpleITK in Python.
I am looping through the files and load a slice with:
reader = sitk.ImageFileReader()
reader.LoadPrivateTagsOn()
reader.SetFileName(img)
image = reader.Execute()
Then I change the tags I would like to anonymize and save the slice
try:
anonymizetags = [("0008|0080", ""), # Inst. Name
("0008|0081", ""), # Inst. Address
("0008|0090", ""), # Referring Physician's Name
("0008|1010", ""), # Station Name
("0008|1030", ""), # Study Description
("0008|1040", ""), # Institutional Department Name
("0008|1048", ""), # Physician(s) of Record
("0008|1070", ""), # Operators' Name
("0010|0010", abbr.replace(chr(56572), '_').replace(chr(56548), '_')+'__'+birthyear), # Patient Name
("0010|0020", "1234567890"), # Patient ID
("0010|0030", "19000101"), # Patient Birthdate
("0010|1040", ""), # Patient Address
("0010|21C0", ""), # Pregnancy Status
("0020|4000", ""), # Image Comments
("0032|1032", ""), # Requesting Physician
("0032|1033", ""), # Requesting Service]
]
for entries in anonymizetags:
image.SetMetaData(entries[0], entries[1])
writer = sitk.ImageFileWriter()
writer.SetFileName(path)
writer.Execute(image)
except:
....
If I only copy the slices, I use copyfile(img, path)
, and here I use the SimpleITK ImageFileWriter
.
A possible workaround might be to first reshuffle the individual slices into the sequence directories and then anonymize, but I would prefer to be able to do this in one run.
Can you give me some pointers on how I can save with the modified tags such that the slices are still recognized to belong to the same image volume?
Best and thank you,
Yannick