1 /*=========================================================================
4 Module: $RCSfile: Anonymize.cxx,v $
6 Date: $Date: 2007/06/15 13:18:50 $
7 Version: $Revision: 1.13 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
23 #include "gdcmArgMgr.h"
28 /// \todo : AnonymizeDirectory
29 /// That should split the images : Patient/Study/Serie
30 /// and keeps coherent the StudyInstanceUID, SeriesInstanceUID
31 /// (Now, a new one is generated fore each image :-( )
32 int main(int argc, char *argv[])
36 " Anonymize a full gdcm-readable Dicom image ",
37 " Warning : probably segfaults if pixels are not gdcm readable. ",
38 " Use AnonymizeNoLoad instead. ",
39 " usage: Anonymize filein=inputFileName fileout=anonymizedFileName[debug] ",
40 " debug : user wants to run the program in 'debug mode' ",
43 // ----- Initialize Arguments Manager ------
44 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
46 if (argc == 1 || am->ArgMgrDefined("usage"))
48 am->ArgMgrUsage(usage); // Display 'usage'
52 char *fileName = am->ArgMgrWantString("filein",usage);
53 if ( fileName == NULL )
59 char *outputFileName = am->ArgMgrWantString("fileout",usage);
60 if ( outputFileName == NULL )
65 if (am->ArgMgrDefined("debug"))
66 GDCM_NAME_SPACE::Debug::DebugOn();
68 // if unused Param we give up
69 if ( am->ArgMgrPrintUnusedLabels() )
71 am->ArgMgrUsage(usage);
76 delete am; // we don't need Argument Manager any longer
78 // ============================================================
79 // Read the input file.
80 // ============================================================
82 GDCM_NAME_SPACE::File *f;
84 f = GDCM_NAME_SPACE::File::New( );
85 f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL );
86 f->SetFileName( fileName );
91 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
92 << "DICOM / ACR File" <<std::endl;
96 std::cout << " ... is readable " << std::endl;
98 // ============================================================
99 // Load the pixels in memory.
100 // ============================================================
102 // We need a gdcm::FileHelper, since we want to load the pixels
103 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
105 // unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one !
106 // Feel free to cast if you know it's not.
108 uint8_t *imageData = fh->GetImageData();
110 if ( imageData == 0 )
112 std::cerr << "Sorry, Pixels of" << fileName <<" are not "
113 << " gdcm-readable." << std::endl
114 << "Use exAnonymizeNoLoad" << std::endl;
120 // ============================================================
121 // Choose the fields to anonymize.
122 // ============================================================
124 f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo");
126 f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas^X");
128 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
129 // Study Instance UID
130 f->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
132 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
134 // Aware user will add here more fields to anonymize here
136 // The gdcm::File is modified in memory
140 // ============================================================
142 // ============================================================
144 // Since we just Anonymized the file, we know that no modification
145 // was performed on the pixels.
146 // The written image will not appear as a 'Secondary Captured image'
147 // nor as a DERIVED one
149 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
151 fh->WriteDcmExplVR(outputFileName);
152 std::cout <<"End Anonymize" << std::cout;
154 // ============================================================
155 // Remove the Anonymize list
156 // ============================================================
157 f->ClearAnonymizeList();