A clinical-grade tool for batch anonymization of DICOM medical images, removing patient identifiable information while preserving essential imaging data for research and analysis.
This skill anonymizes DICOM (Digital Imaging and Communications in Medicine) files by removing or replacing Protected Health Information (PHI) while maintaining the integrity of the medical image data. It supports batch processing of entire directories and generates audit logs for compliance documentation.
bash
# Anonymize a single file
python scripts/main.py --input patient_scan.dcm --output anonymized.dcm
# Batch process a directory
python scripts/main.py --input /path/to/dicom/folder/ --output /path/to/output/ --batch
# Preserve study relationships with pseudonyms
python scripts/main.py --input scans/ --output clean/ --batch --preserve-studies
# Custom anonymization (keep age, remove birth date)
python scripts/main.py --input scan.dcm --output clean.dcm --keep-tags PatientAge
python
from scripts.main import DICOMAnonymizer
anonymizer = DICOMAnonymizer(preserve_studies=True)
result = anonymizer.anonymize_file("input.dcm", "output.dcm")
print(f"Tags anonymized: {len(result.anonymized_tags)}")
# Batch processing
results = anonymizer.anonymize_directory("input_folder/", "output_folder/")
ParameterTypeDefaultRequiredDescription--input, -istring-YesInput DICOM file or directory path--output, -ostring-YesOutput DICOM file or directory path--batch, -bflagfalseNoEnable batch/directory processing--preserve-studiesflagfalseNoMaintain study relationships with pseudonyms--keep-tagsstring-NoComma-separated list of tags to preserve--remove-privateflagtrueNoRemove private/unknown tags--audit-logstring-NoPath for JSON audit log--overwriteflagfalseNoOverwrite existing output files
The following PHI tags are anonymized by default:
TagAttributeAction(0010,0010)PatientNameRemoved / Replaced(0010,0020)PatientIDHashed / Pseudonym(0010,0030)PatientBirthDateRemoved(0010,0040)PatientSexPreserved (demographic research)(0010,1010)PatientAgePreserved (calculated from birth date)(0010,1020)PatientSizePreserved(0010,1030)PatientWeightPreserved
TagAttributeAction(0008,0080)InstitutionNameRemoved(0008,0081)InstitutionAddressRemoved(0008,0090)ReferringPhysicianNameRemoved(0008,1048)PhysiciansOfRecordRemoved(0008,1050)PerformingPhysicianNameRemoved(0008,1060)NameOfPhysiciansReadingStudyRemoved(0008,1070)OperatorsNameRemoved
TagAttributeAction(0008,0050)AccessionNumberHashed / Removed(0020,0010)StudyIDHashed (if preserve-studies)(0020,000D)StudyInstanceUIDHashed (if preserve-studies)(0020,000E)SeriesInstanceUIDHashed (if preserve-studies)(0020,4000)ImageCommentsRemoved
TagAttributeAction(0018,1030)ProtocolNamePreserved / Anonymized(0018,1000)DeviceSerialNumberRemoved(0008,1010)StationNameRemoved(0008,0018)SOPInstanceUIDRegenerated
json
{
"timestamp": "2024-01-15T10:30:00Z",
"input_file": "/path/to/original.dcm",
"output_file": "/path/to/anonymized.dcm",
"original_patient_id_hash": "sha256:abc123...",
"pseudonym": "ANON_0001",
"tags_anonymized": [
{"tag": "(0010,0010)", "attribute": "PatientName", "action": "cleared"},
{"tag": "(0010,0020)", "attribute": "PatientID", "action": "hashed"},
{"tag": "(0010,0030)", "attribute": "PatientBirthDate", "action": "cleared"}
],
"statistics": {
"total_tags_processed": 150,
"phi_tags_removed": 12,
"private_tags_removed": 5,
"image_data_preserved": true
}
}
See references/requirements.txt for full dependency list.
⚠️ CRITICAL: This tool is designed as a helper, not a replacement for institutional review.
references/dicom_standard_ps3.15.pdf - DICOM Standard Part 15: Security and System Managementreferences/hipaa_deidentification_guide.pdf - HIPAA Safe Harbor de-identification standardsreferences/phi_tags.json - Complete list of PHI-related DICOM tagsreferences/requirements.txt - Python dependenciesComplex DICOM data structures, UID management, regulatory compliance requirements, potential pixel-data PHI.
Risk IndicatorAssessmentLevelCode ExecutionPython/R scripts executed locallyMediumNetwork AccessNo external API callsLowFile System AccessRead input files, write output filesMediumInstruction TamperingStandard prompt guidelinesLowData ExposureOutput files saved to workspaceLow
bash
# Python dependencies
pip install -r requirements.txt
Current Stage: Draft
Next Review Date: 2026-03-06
Known Issues: None
Planned Improvements: