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.

dicomFile = 'CT-MONO2-16-ankle.dcm';
I = dicomread(dicomFile);

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',[])

Read the metadata from the DICOM file.

info = dicominfo(dicomFile);

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.

dicomFileNotAnon = 'ankle_notAnon.dcm';
dicomwrite(I,dicomFileNotAnon,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(dicomFileNotAnon);
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 property.

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.

dicomFileAnon = 'ankle_anon.dcm'
dicomFileAnon = 
'ankle_anon.dcm'
dicomanon(dicomFileNotAnon,dicomFileAnon);

Read the metadata from the anonymized DICOM file.

infoAnon = dicominfo(dicomFileAnon);

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 property.

infoAnon.SeriesInstanceUID
ans = 
'1.3.6.1.4.1.9590.100.1.2.332976487717284553325912857110685666132'

See Also

Apps

Functions

Related Topics