LAUREL BRIDGE

LaurelBridge.DCFExamples.Anonymizer Namespace

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

  ClassDescription
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 http://xca.sourceforge.net/ 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.

Remarks

Supported OS Platforms:

  • Windows - .Net Framework 4.7.2 64-bit and 32-bit
  • Windows - .Net Core 2.1 64-bit and 32-bit
  • Linux - .Net Core 2.1 64-bit

Examples

Anonymizer Sample Code
public class Program
{
    /// <summary>
    /// Main program for Anonymizer.
    /// </summary>
    public static void Main()
    {

        Console.WriteLine("DCF Library using target framework {0}", DCFVersion.TargetFramework);

        try
        {
            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);

            // Since version 3.4.22, the default encryption algorithm used for de-identification is AES (Advanced Encryption Standard).
            // AES is strongly recommended as it is more secure than Triple DES (Data Encryption Standard).
            // Uncomment the following line if you wish to use Triple DES encryption.
            //cfgSettings.EncryptionAlgorithm = EncryptionUtils.EncryptionAlgorithm.TripleDes;

            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))
                {
                    dfo.WriteDataSet(deIdentifiedDataSet);
                    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 deIdentifiedDataSet = dfi.ReadDataSet();

                // returns the reidentified dataset using the given settings from the configuration
                DicomDataSet reIdentifiedDataSet = ConfidentialityProfileUtils.ReIdentifyDicomDataSet(deIdentifiedDataSet, 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))
                {
                    dfo.WriteDataSet(reIdentifiedDataSet);
                    Console.WriteLine("Reidentified dataset saved to file: {0}", deidentifiedFilename);
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught during execution: {0}", e);
            Environment.ExitCode = 1;
        }

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