[Insight-developers] anonymize DICOM files
Kent Williams
norman-k-williams at uiowa.edu
Thu Feb 3 18:26:17 EST 2005
I have several DICOM data sets that for one reason or another are not
working properly with the gdcm Dicom reader. The problems we're having
aren't a big deal -- and I can deal with it off the list with the GDCM
guy -- but I need to anonymize the datasets before sending them offsite.
My idea was to write a simple app that anonymizes the header and dumps a
new file out. gdcm::Header has a function called 'AnonymizeHeader' that
I copied to blank out the problem fields, but it's not clear to me how
to read in the whole dicom slice and write it back out along with the
pixel data -- using GDCM.
What's happening is that it appears the header is getting written out OK
but the pixel data is not.
Below is the program I wrote -- clearly I'm missing the 'read in the
data from the input data, attach it to the output file stage.'
I would have used an anonymizer someone else wrote -- if there was one I
could trust, that was free, and didn't have a stupid user interface!
Google didn't find anything like that!
#include "gdcm.h"
#include "unistd.h"
int
main(int argc, char **argv)
{
char *inputfilename(0),
*outputfilename(0);
int c;
bool quitopt = false;
while(!quitopt && (c = getopt(argc,argv,"i:o:")) != -1)
{
switch(c)
{
case 'i':
inputfilename = optarg;
break;
case 'o':
outputfilename = optarg;
break;
default:
quitopt = true;
break;
}
}
if(inputfilename == 0)
{
std::cerr << "No input file given" << std::endl;
exit(-1);
}
if(outputfilename == 0)
{
std::cerr << "No output file given" << std::endl;
exit(-1);
}
std::string InputFilename(inputfilename),
OutputFilename(outputfilename);
gdcm::Header h(InputFilename);
if(!h.IsReadable())
{
std::cerr << "Can't open input file " << inputfilename << std::endl;
exit(-1);
}
// If exist, replace by spaces
h.SetEntryByNumber (" ",0x0010, 0x2154); // Telephone
h.SetEntryByNumber (" ",0x0010, 0x1040); // Adress
h.SetEntryByNumber (" ",0x0010, 0x0020); // Patient ID
gdcm::DocEntry* patientNameHE = h.GetDocEntryByNumber (0x0010, 0x0010);
if ( patientNameHE ) // we replace it with bogus name
{
h.ReplaceOrCreateByNumber("Ernest_T_Bass", 0x0010, 0x0010);
}
gdcm::File f(&h);
f.WriteDcmExplVR(OutputFilename);
}
More information about the Insight-developers
mailing list