Main Content

Remove Confidential Information from DICOM File

This example shows how to anonymize a DICOM file.

When using a DICOM file as part of a training set, blinded study, or a presentation, you might want to remove confidential patient information, a process called anonymizing the file. To do this, use the dicomanon function.

Read an image from a DICOM file into the workspace.

filename = "CT-MONO2-16-ankle.dcm";
I = dicomread(filename);

Display the image. Because the DICOM image data is signed 16-bit data, automatically scale the display range so that the minimum pixel value is black and the maximum pixel value is white.

imshow(I,DisplayRange=[])

Figure contains an axes object. The hidden axes object contains an object of type image.

Read the metadata from the DICOM file.

info = dicominfo(filename);

The DICOM file in this example has already been anonymized for patient privacy. To create an informative test DICOM file, set the PatientName with an artificial value using the Person Name (PN) value representation.

info.PatientName = 'Doe^John';

Write the image with modified metadata to a new DICOM file.

filenameNotAnon = "ankle_notAnon.dcm";
dicomwrite(I,filenameNotAnon,info);

Read the metadata from the non-anonymous DICOM file, then confirm that the patient name in the new file is not anonymous.

infoNotAnon = dicominfo(filenameNotAnon);
infoNotAnon.PatientName
ans = struct with fields:
    FamilyName: 'Doe'
     GivenName: 'John'

To identify the series to which the non-anonymous image belongs, display the value of the SeriesInstanceUID field.

infoNotAnon.SeriesInstanceUID
ans = 
'1.2.840.113619.2.1.2411.1031152382.365.736169244'

Anonymize the file using the dicomanon function. The function creates a new series with new study values, changes some of the metadata, and then writes the image to a new file.

filenameAnon = "ankle_anon.dcm";
dicomanon(filenameNotAnon,filenameAnon);

Read the metadata from the anonymized DICOM file.

infoAnon = dicominfo(filenameAnon);

Confirm that the patient name information has been removed.

infoAnon.PatientName
ans = struct with fields:
    FamilyName: ''
     GivenName: ''
    MiddleName: ''
    NamePrefix: ''
    NameSuffix: ''

Confirm that the anonymous image belongs to a new study by displaying the value of the SeriesInstanceUID field.

infoAnon.SeriesInstanceUID
ans = 
'1.3.6.1.4.1.9590.100.1.4.368876687834840139129966219474167171681'

See Also

Apps

Functions

Related Topics