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(___,'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. Use this syntax to preserve the Study/Series/Image hierarchy or to replace a specific value with a more generic property (such as removing PatientBirthDate but keeping a computed PatientAge).

dicomanon(___,Name,Value) uses name-value pairs 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 hierarchy.

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

Input Arguments

collapse all

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

Data Types: char | string

Name of 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 cell array of field names.

Names of the attributes to preserve, specified as a structure whose fields are attribute names. The structure values are the attribute values to preserve.

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: dicomanon('CT-MONO2-16-ankle.dcm','CT-MONO2-16-ankle_anon.dcm','UseVRHeuristic',false)

Write nonstandard attributes to the anonymized file, specified as the comma-separated pair consisting of 'WritePrivate' and false or true.

When set to true, then dicomanon includes private extensions in the file, which could compromise patient confidentiality.

Data Types: logical

Read noncompliant DICOM files that switch value representation (VR) modes incorrectly, specified as the comma-separated pair consisting of 'UseVRHeuristic' and true or false.

When 'UseVRHeuristic' is true (the default), then dicomanon instructs the parser to use a heuristic to help read certain noncompliant files which switch value representation (VR) modes incorrectly. A small number of compliant files will not be read correctly. dicomanon displays a warning if the heuristic is employed. Set 'UseVRHeuristic' to false to read these compliant files. Compliant files are always written.

Data Types: logical


Introduced before R2006a