Main Content


Anonymize DICOM file



dicomanon(file_in,file_out) removes confidential medical information from the DICOM file file_in and creates a new file file_out with the modified values. Image data and other attributes are unmodified.

dicomanon(file_in,file_out,"keep",fields) modifies all of the confidential data except for those listed in fields. This syntax is useful for keeping metadata that does not uniquely identify the patient but is useful for diagnostic purposes (such as PatientAge and PatientSex).


Keeping certain fields might compromise patient confidentiality.

dicomanon(___,"update",attributes) modifies the confidential data and updates particular confidential data listed in attributes, in addition to any combination of input arguments from previous syntaxes. Use this syntax to preserve the Study/Series/Image hierarchy, or to replace a specific value with a more generic attribute (such as removing PatientBirthDate but keeping a computed PatientAge).

dicomanon(___,Name,Value) uses name-value arguments to provide additional options to the parser.


collapse all

Create a version of a DICOM file with all the personal information removed.


Create a version of a DICOM file with personal information removed, keeping certain fields that could be useful for training.


Anonymize a series of images, keeping the study and series hierarchy.

values.StudyInstanceUID = dicomuid;
values.SeriesInstanceUID = dicomuid;
d = dir("*.dcm");
for p = 1:numel(d)
	dicomanon(d(p).name, sprintf("anon%d.dcm",p), ...

Input Arguments

collapse all

Name of the DICOM file to read, specified as a character vector or string scalar.

Data Types: char | string

Name of the anonymized DICOM file to write, specified as a character vector or string scalar.

Data Types: char | string

Names of the fields to preserve, specified as a string array or cell array of character vectors containing metadata attribute names.

Attributes to update, specified as a structure whose fields are the names of the DICOM metadata attributes you want to update. The value of each field specifies the new value for the attribute.

To update nested metadata attributes, specify attributes as a structure containing the corresponding top level attribute with all of its nested attributes, both modified and unmodified. If you exclude nested attributes from attributes, dicomanon deletes them before writing the new anonymized DICOM file.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: dicomanon("CT-MONO2-16-ankle.dcm","CT-MONO2-16-ankle_anon.dcm",UseVRHeuristic=false) reads the metadata from the original DICOM file without using a heuristic.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: dicomanon("CT-MONO2-16-ankle.dcm","CT-MONO2-16-ankle_anon.dcm","UseVRHeuristic",false) reads the metadata from the original DICOM file without using a heuristic.

Write nonstandard attributes to the anonymized file, specified as a logical 0 (false) or 1 (true).

When set to true, the function includes private metadata attributes in the file. These attributes could compromise patient confidentiality.

Data Types: logical

Read noncompliant DICOM files that switch value representation (VR) modes incorrectly, specified as a logical 1 (true) or 0 (false).

When set to true, dicomanon uses a heuristic to help read certain noncompliant DICOM files that switch VR modes incorrectly. dicomanon displays a warning if it uses this heuristic. If this heuristic is enabled, a small number of compliant files are not read correctly. Set UseVRHeuristic to false to read these compliant files.

Data Types: logical


Version History

Introduced before R2006a