2

Given i am very naive in C# and using fo-dicom package, i have been finding challenging how to use different security profiles for DicomAnonymizer as listed here: https://fo-dicom.github.io/html/fff31967-d92f-28da-3106-d4ab34b9b65b.htm.

I tried following but doesn't work:

DicomAnonymizer.SecurityProfile SecurityProfile = 1;
var anony = new DicomAnonymizer();
anony.Anonymize(testfile);

I want to test how each of these security profile affects dicom header. For the same i am fiddling with syntax of using this? Can someone share any example code?

johnny 5
  • 19,893
  • 50
  • 121
  • 195
KashiVish
  • 41
  • 5

3 Answers3

2

One needs to create security profile object using static method LoadProfile first and then use in DicomAnonymizer constructor as follows:

var profile = DicomAnonymizer.SecurityProfile.LoadProfile(null, DicomAnonymizer.SecurityProfileOptions.CleanGraph);
var anony = new DicomAnonymizer();
KashiVish
  • 41
  • 5
  • 1
    I used as following. var profile = DicomAnonymizer.SecurityProfile.LoadProfile(null, DicomAnonymizer.SecurityProfileOptions.BasicProfile | DicomAnonymizer.SecurityProfileOptions.RetainUIDs ); var dicomAnonymizer = new DicomAnonymizer(profile); – ozgurozkanakdemirci Mar 25 '19 at 16:18
  • Calling **just** the *DicomAnonymizer.SecurityProfile.LoadProfile(...)* **before** creating an instance of the DicomAnonymizer class, **doesn't seem to be of any effect**. The *LoadProfile(...)* method, imho, has a wrong name, as it suggests a profile to be loaded in some static-ish way. The *SecurityProfile* class instance that is returned by the *LoadProfile(...)* method must be passed to the *DicomAnonymizer.ctor(...)*, instead, otherwise it will be replaced by a default one using the *DicomAnonymizer.SecurityProfileOptions.BasicProfile* flag only. – Sume Nov 20 '19 at 15:52
2

An other issue I see in your code: DicomDataset DicomAnonymizer.Anonymize(DicomDataset) takes a DicomDataset as parameter and returns a new anonymized copy. This is recommended if you do not want the original DicomDataset to be modified. But therefore you take into account to duplicate lot of data in memory. The other method is void DicomAnonymizer.AnonymizeInPlace(DicomDataset), which directly manipulates the data in the DicomDataset.

Your code above uses the first method, but does not store the returned anonymized DicomDataset into a variable, so it is released to the garbage collector immediatelly.

Call var anonymizedTestfile = anony.Anonymize(testfile); or anony.AnonymizeInPlace(testfile);

gofal3
  • 1,213
  • 10
  • 16
0

If you look into the definition of the enum SecurityProfileOptions you will find both that the enum is marked as [Flags] and it has the following values defined:

BasicProfile = 1,
RetainSafePrivate = 2,
RetainUIDs = 4,
RetainDeviceIdent = 8,
RetainPatientChars = 16, // 0x0010
RetainLongFullDates = 32, // 0x0020
RetainLongModifDates = 64, // 0x0040
CleanDesc = 128, // 0x0080
CleanStructdCont = 256, // 0x0100
CleanGraph = 512, // 0x0200

Short answer to your question: you can make use of the [Flags] attribute to store more than a value of an enum at a time by using the bitwise or operand like it follows:

SecurityProfileOptions.BasicProfile | SecurityProfileOptions.RetainDeviceIndent

I highly suggest you to look better at this question.

Back to your specific question, the usage of the profile you should be making is the following one:

DicomAnonymizer.SecurityProfile securityProfile = DicomAnonymizer.SecurityProfile.LoadProfile(null, DicomAnonymizer.SecurityProfileOptions.BasicProfile | DicomAnonymizer.SecurityProfileOptions.CleanDesc |... [add as many as you want from that enum]);
  DicomAnonymizer dicomAnonymizer = new DicomAnonymizer(securityProfile);
Sume
  • 93
  • 1
  • 6