LaurelBridge.DCF.Examples.Anonymizer Namespace

LaurelBridge.DCF.Examples.Anonymizer Namespace

DICOM Connectivity Framework V3.4
The Anonymizer example demonstrates how to use the DCF to deidentify and reidentify a DICOM dataset.

Public classProgram
Deidentify a dataset with the purpose of removing any patient identifying information. Then reidentify the deidentified dataset to show the reconstruction of the anonymized Dicom dataset. This example uses the AnonymizerSettings.cfg file to indicate the location of the required public and private certificates.

The certificates that are provided in this example project are for demonstration purposes only. These should be replaced with your public and/or private certificate files, depending upon your application.

The utility at is helpful for viewing and editing certificates. For this demo application: the public certificate (export format PEM) is stored in DAnon.crt; the private certificate (export format PKCS #12) DAnon.p12; and the password for the private certificate is "danon".

The deidentification process configured in this example also demonstrates anonymizing the pixel data of the dataset. The deidentified example image will have a black bar on the top and bottom of the deidentified dataset's image.


Anonymizer Sample Code
public class Program
    /// <summary>
    /// Main program for Anonymizer.
    /// </summary>
    public static void Main()
            string cfgName = "AnonymizerSettings.cfg";
            string inputFilename = "mr-knee.dcm";
            string deidentifiedFilename = "mr-knee-anonymized.dcm";
            string reidentifiedFilename = "mr-knee-restored.dcm";

            CFGGroup cfg = CFGDB.loadGroupFromFile(cfgName);
            ConfigurationSettings cfgSettings = ConfigurationSettings.FromCFG(cfg);
            DicomSessionSettings dss = new DicomSessionSettings() { SessionName = "Anonymizer" };

            // DeIdentify the input dataset. This assumes the public certificate path is properly set in the anonymization
            // settings configuration.
            using (DicomFileInput dfi = new DicomFileInput(inputFilename, String.Empty, dss))
                DicomDataSet originalDataSet = dfi.ReadDataSet();

                // returns the deidentified dataset using the given settings from the configuration
                DicomDataSet deIdentifiedDataSet = ConfidentialityProfileUtils.DeIdentifyDicomDataSet(originalDataSet, dss, cfgSettings);
                Console.WriteLine("Input dataset ({0}) successfully deidentified", inputFilename);
                // Save the deidentified dataset out to disk using the specified filename
                using (DicomFileOutput dfo = new DicomFileOutput(deidentifiedFilename, Uids.ELE, dss))
                    Console.WriteLine("deidentified dataset saved to file: {0}", deidentifiedFilename);

            // ReIdentify the given anonymized dataset. This assumes the public and private certificate paths are 
            // properly set in the anonymization settings configuration, as well as the private certificate password.
            using (DicomFileInput dfi = new DicomFileInput(deidentifiedFilename, String.Empty, dss))
                DicomDataSet deIdentfiedDataSet = dfi.ReadDataSet();

                // returns the reidentified dataset using the given settings from the configuration
                DicomDataSet reIdentifiedDataSet = ConfidentialityProfileUtils.ReIdentifyDicomDataSet(deIdentfiedDataSet, dss, cfgSettings);
                Console.WriteLine("Input deidentified dataset ({0}) successfully reidentified", deidentifiedFilename);

                // Save decrypted dataset out to disk using the specified filename
                using (DicomFileOutput dfo = new DicomFileOutput(reidentifiedFilename, Uids.ELE, dss))
                    Console.WriteLine("Reidentified dataset saved to file: {0}", deidentifiedFilename);
        catch (Exception e)
            Console.WriteLine("Exception caught during execution: {0}", e);

        if (System.Diagnostics.Debugger.IsAttached)
            Console.Write("Press any key to continue . . . ");