1 /*=========================================================================
4 Module: $RCSfile: Anonymize.cxx,v $
6 Date: $Date: 2005/06/07 11:12:10 $
7 Version: $Revision: 1.1 $
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"
27 int main(int argc, char *argv[])
31 " Anonymize a full gdcm-readable Dicom image",
32 " Warning : probably segfaults if pixels are not gdcm readable.",
33 " Use exAnonymizeNoLoad instead.",
34 " usage: Anonymize filein=inputFileName fileout=anonymizedFileName[debug] ",
35 " debug : user wants to run the program in 'debug mode' ",
38 // ----- Initialize Arguments Manager ------
39 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
41 if (am->ArgMgrDefined("usage"))
43 am->ArgMgrUsage(usage); // Display 'usage'
47 char *fileName = am->ArgMgrWantString("filein",usage);
48 if ( fileName == NULL )
54 char *outputFileName = am->ArgMgrWantString("fileout",usage);
55 if ( outputFileName == NULL )
60 if (am->ArgMgrDefined("debug"))
61 gdcm::Debug::DebugOn();
63 // if unused Param we give up
64 if ( am->ArgMgrPrintUnusedLabels() )
66 am->ArgMgrUsage(usage);
71 delete am; // we don't need Argument Manager any longer
73 // ============================================================
74 // Read the input file.
75 // ============================================================
79 f1 = new gdcm::File( fileName );
80 if (!f1->IsReadable())
82 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
83 << "DICOM / ACR File" <<std::endl;
87 std::cout << " ... is readable " << std::endl;
89 // ============================================================
90 // Load the pixels in memory.
91 // ============================================================
93 // We need a gdcm::FileHelper, since we want to load the pixels
94 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
96 // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one)
98 uint8_t *imageData = fh1->GetImageData();
100 if ( imageData == 0 )
102 std::cerr << "Sorry, Pixels of" << fileName <<" are not "
103 << " gdcm-readable." << std::endl
104 << "Use exAnonymizeNoLoad" << std::endl;
110 // ============================================================
111 // Choose the fields to anonymize.
112 // ============================================================
114 f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo");
116 f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");
118 f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
119 // Study Instance UID
120 f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
122 f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
124 // Aware user will add more fields to anonymize here
126 // The gdcm::File is modified in memory
130 // ============================================================
132 // ============================================================
134 fh1->WriteDcmExplVR(outputFileName);
135 std::cout <<"End Anonymize" << std::cout;
137 // ============================================================
138 // Remove the Anonymize list
139 // ============================================================
140 f1->ClearAnonymizeList();