1 /*=========================================================================
4 Module: $RCSfile: Anonymize.cxx,v $
6 Date: $Date: 2006/03/01 09:51:56 $
7 Version: $Revision: 1.10 $
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 AnonymizeNoLoad 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 (argc == 1 || 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 f = gdcm::File::New( );
80 f->SetLoadMode( gdcm::LD_ALL );
81 f->SetFileName( fileName );
86 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
87 << "DICOM / ACR File" <<std::endl;
91 std::cout << " ... is readable " << std::endl;
93 // ============================================================
94 // Load the pixels in memory.
95 // ============================================================
97 // We need a gdcm::FileHelper, since we want to load the pixels
98 gdcm::FileHelper *fh = gdcm::FileHelper::New(f);
100 // unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one !
101 // Feel free to cast if you know it's not.
103 uint8_t *imageData = fh->GetImageData();
105 if ( imageData == 0 )
107 std::cerr << "Sorry, Pixels of" << fileName <<" are not "
108 << " gdcm-readable." << std::endl
109 << "Use exAnonymizeNoLoad" << std::endl;
115 // ============================================================
116 // Choose the fields to anonymize.
117 // ============================================================
119 f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo");
121 f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas^X");
123 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
124 // Study Instance UID
125 f->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
127 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
129 // Aware user will add here more fields to anonymize here
131 // The gdcm::File is modified in memory
135 // ============================================================
137 // ============================================================
139 // Since we just Anonymized the file, we know no modification
140 // was performed on the pixels.
141 // The written image will not appear as a 'Secondary Captured image'
142 // nor as a DERIVED one
144 fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
146 fh->WriteDcmExplVR(outputFileName);
147 std::cout <<"End Anonymize" << std::cout;
149 // ============================================================
150 // Remove the Anonymize list
151 // ============================================================
152 f->ClearAnonymizeList();