Function Repository Resource:

DICOMAnonymize

Source Notebook

Anonymize DICOM files by removing or replacing metadata that could lead to identification of a patient

Contributed by: Bartosz Białoskórski

ResourceFunction["DICOMAnonymize"]["infile","outfile"]

creates DICOM file "outfile" containing same image data as "infile" but with an anonymized version of the original metadata.

Details and Options

The following option values are supported for the option "AnonymizationLevel":
"Basic"anonymization of most commonly occuring tags
"Full"anonymization of extensive list of tags
The default "AnonymizationLevel" value is "Basic".
Values for tags PatientID and StudyID are randomly generated.
All UID tags except for the following are being replaced with newly generated UID if present:
GroupElementTag Name
00000002AffectedSOPClassUID
00020003RequestedSOPClassUID
00020002MediaStorageSOPClassUID
00020003MediaStorageSOPInstanceUID
00020010TransferSyntaxUID
00020012ImplementationClassUID
00080016SOPClassUID
00080016SOPInstanceUID
The following is a list of tags affected by "AnonymizationLevel""Basic":
GroupElementTag NameAction
00100010PatientNameReplace with "Anonymous^Patient"
00100030PatientBirthDateReplace with "19700101"
00100032PatientBirthTimeReplace with"000000"
00100040PatientSexEmpty
00101005PatientBirthNameEmpty
00101002OtherPatientIDsSequenceEmpty
00101001OtherPatientNamesEmpty
00101010PatientAgeReplace with "000Y"
00101020PatientSizeEmpty
00101030PatientWeightEmpty
00101090MedicalRecordLocatorEmpty
00102160EthnicGroupEmpty
00102180OccupationEmpty
001021B0AdditionalPatientHistoryEmpty
00104000PatientCommentsEmpty
00080080InstitutionNameEmpty
00080081InstitutionAddressEmpty
00080090ReferringPhysicianNameEmpty
00080092ReferringPhysicianAddressEmpty
00080094ReferringPhysicianTelephoneNumbersEmpty
00080020StudyDateReplace with "19700101"
00080030StudyTimeReplace with "000000.000000"
00080021SeriesDateReplace with"19700101"
00080031SeriesTimeReplace with "000000"
00081030StudyDescriptionEmpty
00081048PhysiciansOfRecordEmpty
00081050PerformingPhysicianNameEmpty
00081060NameOfPhysiciansReadingStudyEmpty
00081080AdmittingDiagnosesDescriptionEmpty
00321040StudyArrivalDateReplace with "19700101"
00321041StudyArrivalTimeReplace with "000000"
0008103ESeriesDescriptionEmpty
00081070OperatorsNameEmpty
00204000ImageCommentsEmpty
00081010StationNameEmpty
00181000DeviceSerialNumberEmpty
00082111DerivationDescriptionEmpty
00181030ProtocolNameEmpty
Option value "Full" additionally affects the following tags:
GroupElementTag NameAction
00100021IssuerOfPatientIDEmpty
00101040PatientAddressEmpty
00101060PatientMotherBirthNameEmpty
00101080MilitaryRankEmpty
00101081BranchOfServiceEmpty
00102150CountryOfResidenceEmpty
00102152RegionOfResidenceEmpty
00102154PatientTelephoneNumbersEmpty
001021F0PatientReligiousPreferenceEmpty
00380010AdmissionIDEmpty
00380021AdmittingTimeReplace with "000000"
00380020AdmittingDateReplace with "19700101"
00380032DischargeTimeReplace with "000000"
00380030DischargeDateReplace with "19700101"
0038001BScheduledAdmissionTimeReplace with "000000"
0038001AScheduledAdmissionDateReplace with "19700101"
0038001DScheduledDischargeTimeReplace with "000000"
0038001CScheduledDischargeDateReplace with "19700101"
0038001EScheduledPatientInstitutionResidenceEmpty
00380300CurrentPatientLocationEmpty
00380400PatientInstitutionResidenceEmpty
00384000VisitCommentsEmpty
00080050AccessionNumberEmpty
00320012StudyIDIssuerEmpty
00320033StudyVerifiedTimeReplace with "000000"
00320032StudyVerifiedDateReplace with "19700101"
00320035StudyReadTimeReplace with "000000"
00320034StudyReadDateReplace with "19700101"
00321001ScheduledStudyStartTimeReplace with "000000"
00321000ScheduledStudyStartDateReplace with "19700101"
00321011ScheduledStudyStopTimeReplace with "000000"
00321010ScheduledStudyStopDateReplace with "19700101"
00321020ScheduledStudyLocationEmpty
00321021ScheduledStudyLocationAETitleEmpty
00321030ReasonForStudyEmpty
00321032RequestingPhysicianEmpty
00321033RequestingServiceEmpty
00321051StudyCompletionTimeReplace with "000000"
00321050StudyCompletionDateReplace with "19700101"
00321060RequestedProcedureDescriptionEmpty
00324000StudyCommentsEmpty
00402001ReasonForTheImagingServiceRequestEmpty
00402005IssueTimeOfImagingServiceRequestReplace with "000000"
00402004IssueDateOfImagingServiceRequestReplace with "19700101"
00402008OrderEnteredByEmpty
00402009OrderEntererLocationEmpty
00402010OrderCallbackPhoneNumberEmpty
00402400ImagingServiceRequestCommentsEmpty
00400001ScheduledStationAETitleEmpty
00400003ScheduledProcedureStepStartTimeReplace with "000000"
00400002ScheduledProcedureStepStartDateReplace with "19700101"
00400005ScheduledProcedureStepEndTimeReplace with "000000"
00400004ScheduledProcedureStepEndDateReplace with "19700101"
00400006ScheduledPerformingPhysicianNameEmpty
00400007ScheduledProcedureStepDescriptionEmpty
00400400CommentsOnTheScheduledProcedureStepEmpty
00400010ScheduledStationNameEmpty
00400011ScheduledProcedureStepLocationEmpty
00400241PerformedStationAETitleEmpty
00400242PerformedStationNameEmpty
00400243PerformedLocationEmpty
00400245PerformedProcedureStepStartTimeReplace with "000000"
00400244PerformedProcedureStepStartDateReplace with "19700101"
00404050PerformedProcedureStepStartDateTimeReplace with "19700101000000"
00400251PerformedProcedureStepEndTimeReplace with "000000"
00400250PerformedProcedureStepEndDateReplace with "19700101"
00404051PerformedProcedureStepEndDateTimeReplace with "19700101000000"
00400254PerformedProcedureStepDescriptionEmpty
00400255PerformedProcedureTypeDescriptionEmpty
00400280CommentsOnThePerformedProcedureStepEmpty
00401002ReasonForTheRequestedProcedureEmpty
00401004PatientTransportArrangementsEmpty
00401400RequestedProcedureCommentsEmpty
00080013InstanceCreationTimeReplace with "000000"
00080012InstanceCreationDateReplace with "19700101"
00080022AcquisitionDateReplace with "19700101"
00080032AcquisitionTimeReplace with "000000"
0008002AAcquisitionDateTimeReplace with "19700101000000"
00080023ContentDateReplace with "19700101"
00080033ContentTimeReplace with "000000"
40080042ResultsIDIssuerEmpty
40080300ImpressionsEmpty
40084000ResultsCommentsEmpty
40080100InterpretationRecordedDateReplace with "19700101"
40080101InterpretationRecordedTimeReplace with "000000"
40080102InterpretationRecorderEmpty
40080103ReferenceToRecordedSoundEmpty
40080108InterpretationTranscriptionDateReplace with "19700101"
40080109InterpretationTranscriptionTimeReplace with "000000"
4008010AInterpretationTranscriberEmpty
4008010BInterpretationTextEmpty
4008010CInterpretationAuthorEmpty
40080112InterpretationApprovalDateReplace with "19700101"
40080113InterpretationApprovalTimeReplace with "000000"
40080114PhysicianApprovingInterpretationEmpty
40080115InterpretationDiagnosisDescriptionEmpty
40080119DistributionNameEmpty
4008011ADistributionAddressEmpty
40080202InterpretationIDIssuerEmpty
00080070ManufacturerEmpty
00081040InstitutionalDepartmentNameEmpty
00081090ManufacturerModelNameEmpty
00181020SoftwareVersionsEmpty
00181200DateOfLastCalibrationReplace with "19700101"
00181201TimeOfLastCalibrationReplace with "000000"

Examples

Basic Examples (3) 

Extract a sample DICOM file:

In[1]:=
dcmFile = First[ExtractArchive[FindFile["ExampleData/head.dcm.gz"], OverwriteTarget -> True]]
Out[1]=

Perform a basic anonymization:

In[2]:=
ResourceFunction["DICOMAnonymize"][dcmFile, "anon-head.dcm"]

Compare changes to the metadata:

In[3]:=
Complement[Import["anon-head.dcm", "MetaInformation"], Import[dcmFile, "MetaInformation"]]
Out[3]=

Options (2) 

You can choose the level of anonymization:

In[4]:=
dcmFile = First[ExtractArchive[FindFile["ExampleData/head.dcm.gz"], OverwriteTarget -> True]];
ResourceFunction["DICOMAnonymize"][dcmFile, "anon-head-basic.dcm", "AnonymizationLevel" -> "Basic"];
Complement[Import["anon-head-basic.dcm", "MetaInformation"], Import[dcmFile, "MetaInformation"]]
Out[3]=

Now perform stronger anonymization; this will cause more tags to change:

In[5]:=
ResourceFunction["DICOMAnonymize"][dcmFile, "anon-head-full.dcm", "AnonymizationLevel" -> "Full"];
Complement[Import["anon-head-full.dcm", "MetaInformation"], Import[dcmFile, "MetaInformation"]]
Out[6]=

Publisher

Bartosz Białoskórski

Version History

  • 2.0.0 – 03 April 2020
  • 1.0.0 – 01 April 2020

License Information