anonymize
De-identifies a DICOM file, or every DICOM file under a directory, with the Basic Application Level Confidentiality Profile of PS3.15 Annex E and, optionally, one of its options. The input is never changed.
When to use it
Use anonymize before files leave the place they were made: for research,
teaching, a bug report or a second opinion. It removes or replaces the
attributes PS3.15 Table E.1-1 lists, replaces UIDs consistently across the
run so a study stays one study, sets Patient Identity Removed to YES, and
records the method in De-identification Method.
It also deals with text burned into the pixels, which no attribute holds:
an image that may carry it is refused until you say where the text is
(-redact), let a detector find it (-redact auto), or say there is none
(-allow-burned-in).
It does not rename files, so a file name that identifies the patient still does. It does not write a DICOMDIR (write a new one with dicomdir). To hand on a picture rather than a DICOM file, use share.
dcmtk has no single tool for this (dcmodify -ea per attribute comes
closest); pydicom users usually write a script, or use deid.
Examples
One file
go-dicom anonymize scan.dcm clean.dcmDe-identified 1 file(s)go-dicom show clean.dcm::DeidentificationMethod0012,0063 LO 42 Basic Application Confidentiality ProfileA whole study
go-dicom anonymize study/ clean-study/skipped notes.txt: not a DICOM file
De-identified 2 file(s), skipped 1The directory is walked, and each DICOM file is written under the output at the same relative path. Files that are not DICOM are named and left out. Give the whole study in one run: the new UIDs are consistent within a run, not between runs.
Keep the dates, and keep the UID mapping
go-dicom anonymize -profile retain-dates -uid-map uids.json study/ clean-study/{
"1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322": "2.25.71595864987662876829484160226624910532",
…The new UIDs are random 2.25 UIDs, different on every run.
-profile applies one Annex E option on top of the Basic Profile:
clean-descriptors, clean-graphics, clean-structured-content,
retain-dates, retain-patient-characteristics, retain-device-identity,
retain-uids or retain-safe-private.
Caution
The -uid-map file links the output back to the originals, and so to the
patient. Keep it apart from the output, or do not write it.
An ultrasound image with text in the picture
go-dicom anonymize us.dcm clean.dcmError: anonymize: us.dcm: it may hold text burned into the pixels: its modality is US (ultrasound), and Burned In Annotation (0028,0301) does not say there is none. Give -redact x,y,width,height for where the text is, -redact auto to fill what a detector finds, or -allow-burned-in if there is nonego-dicom anonymize -redact 0,0,320,60 us.dcm clean.dcm-redact x,y,w,h fills a rectangle with black in every frame, counted in
pixels from the top left; repeat it for more rectangles. The output says
Burned In Annotation NO and records the Clean Pixel Data Option.
Let a detector find the text
go-dicom anonymize -detect us.dcm248,10,63,43
8,11,78,42
140,19,44,10
…go-dicom anonymize -redact auto us.dcm clean.dcm us.dcm: 10 region(s) detected and filled
De-identified 1 file(s)-detect prints the regions in the form -redact takes and writes nothing.
-redact auto fills them, leaves Burned In Annotation as it was, and records
"Burned-in text redacted where detected, unverified" in the method.
Warning
A detector misses faint, small, handwritten or busy-background text. Look at each image before it leaves you.
Notes
- Unless
-redactis given the pixels are never read into memory; they are copied as the output is written. A redacted compressed image is written uncompressed, so nothing is encoded again and no quality is lost. - An image is taken to hold burned-in text when Burned In Annotation is
YES, or when it is of a kind that often does (ultrasound, endoscopy, secondary and screen captures) and does not sayNO. - When what
-redact autofinds covers more than a quarter of the picture, nothing is filled and that file is not written. - An output file that already exists is overwritten. Writing over the input
itself is refused:
the output is the input; the original would be lost. - Exit status is 0 when every DICOM file was written and 1 on any error.
See also
Options
De-identify a DICOM file or directory
USAGE:
go-dicom anonymize [options] <input> <output>
<input> is a file or a directory. A directory is walked, and each DICOM file
is written under <output> at the same relative path. The input is never
changed.
OPTIONS:
-profile <name> The PS3.15 Annex E option applied on top of the Basic
Profile (default: basic):
basic, clean-descriptors, clean-graphics,
clean-structured-content, retain-dates,
retain-patient-characteristics, retain-device-identity,
retain-uids, retain-safe-private
-uid-map <file> Write the original-to-new UID mapping as JSON. It links
the output back to the patient: keep it apart from the
output, or do not write it.
-redact x,y,w,h Fill a rectangle with black in every frame of every
image, counted in pixels from the top left. Repeat it
for more rectangles. Sets Burned In Annotation to NO and
records the Clean Pixel Data Option.
-redact auto Fill the regions in which a detector finds text. It can
miss: Burned In Annotation is left as it was, and the
method records that the redaction was automatic and
unverified. Look at each image before it leaves you.
When what is found covers more than a quarter of the
picture, more than text does, nothing is filled and
the file is not written.
-detect Print those regions for one file, as -redact takes
them, and write nothing: go-dicom anonymize -detect x.dcm
-allow-burned-in Write images that may hold burned-in text as they are.
-h, -help Show this help message
WHAT IT DOES:
Removes or replaces the attributes PS3.15 Table E.1-1 lists, replaces UIDs
consistently across the run so a study stays one study, sets Patient
Identity Removed, and records the method used. Unless -redact is given,
the pixels are never read into memory: they are copied from the input as
the output is written, so an image of any size takes the memory of its
attributes.
BURNED-IN TEXT:
Ultrasound, endoscopy, secondary captures and screen captures often have
the patient's name drawn into the image, where no attribute holds it. An
image whose Burned In Annotation is YES, or that is of such a kind and does
not say NO, is refused unless -redact says where the text is or
-allow-burned-in says there is none. With rectangles the command does not
find text: they are yours to get right. -redact auto finds it for you and
is not a promise: a detector misses text that is faint, very small, hand
written or drawn over a busy part of the picture, and only a person
looking confirms an image is clean. A compressed image that is redacted
is written uncompressed: nothing is encoded again, so no quality is lost,
and the file is larger.
WHAT IT DOES NOT DO:
File names are kept, so a name that identifies the patient still does.
Files that are not DICOM are left out of the output, and a DICOMDIR is
reported and not written.
EXAMPLES:
go-dicom anonymize scan.dcm clean.dcm
go-dicom anonymize study/ clean-study/
go-dicom anonymize -profile retain-dates study/ clean-study/
go-dicom anonymize -redact 0,0,640,40 ultrasound.dcm clean.dcm
go-dicom anonymize -detect ultrasound.dcm
go-dicom anonymize -redact auto ultrasound.dcm clean.dcmconvert
Writes a DICOM file in another format: DICOM JSON, DICOM XML, a flat JSON or CSV listing of its elements, a NIfTI-1 volume, or a PNG or JPEG picture.
share
Renders a DICOM image as a PNG or JPEG that holds pixels only, refusing an image that may carry burned-in text until you say where the text is or that there is none.