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.


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";

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);
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.

ans = 

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";

Read the metadata from the anonymized DICOM file.

infoAnon = dicominfo(filenameAnon);

Confirm that the patient name information has been removed.

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.

ans = 

See Also



Related Topics