Saving DICOM series after changing tags - individual files not recognized as same series

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()
image = reader.Execute()

Then I change the tags I would like to anonymize and save the slice

    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()


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,


1 Like

Based on your description this should work (I assume all slices also have the same study number, you only indicated that they have the same series number). I would also suggest changing the series number, as it is supposed to be unique and if you don’t change it your original images and the anonymized ones won’t play nicely together. This will confuse programs that use the study-series concepts for loading a volume, if they find both sets of slices, they will belong to a single volume.

Please see this SimpleITK example which reads a DICOM series, modifies it and saves it back in DICOM format.

If this doesn’t resolve your problem please provide additional details (possibly your complete code) so that we can recreate and resolve the issue.