1 /*=========================================================================
4 Module: $RCSfile: exAnonymize.cxx,v $
6 Date: $Date: 2005/07/07 17:31:53 $
7 Version: $Revision: 1.4 $
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"
25 int main(int argc, char *argv[])
27 gdcm::Debug::DebugOn();
28 std::cout << "------------------------------------------------" << std::endl;
29 std::cout << "Anonymize a full gdcm-readable Dicom image" << std::endl;
30 std::cout << " Warning : probably segfaults if pixels are not "
31 << " gdcm readable. Use exAnonymizeNoLoad" << std::endl;
35 std::cerr << "Usage " << argv[0] << " Source image.dcm "
36 << " Output image.dcm " << std::endl;
40 std::string fileName = argv[1];
41 std::string outputFileName = argv[2];
43 // ============================================================
44 // Read the input image.
45 // ============================================================
47 std::cout << argv[1] << std::endl;
49 gdcm::File *f = new gdcm::File();
50 f->SetLoadMode( 0x00000000);
51 f->SetFileName( fileName );
55 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
60 std::cout << " ... is readable " << std::endl;
63 // ============================================================
64 // Load the pixels in memory.
65 // ============================================================
67 // We need a gdcm::FileHelper, since we want to load the pixels
68 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
70 // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one)
72 uint8_t *imageData = fh->GetImageData();
76 std::cerr << "Sorry, Pixels of" << fileName <<" are not "
77 << " gdcm-readable." << std::endl
78 << "Use exAnonymizeNoLoad" << std::endl;
83 // ============================================================
84 // Choose the fields to anonymize.
85 // ============================================================
87 f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo");
89 f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");
91 f->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
93 f->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
95 f->AddAnonymizeElement(0x0010, 0x2154, "3615" );
96 // Aware use will add new fields here
98 // The gdcm::File is modified in memory
102 // ============================================================
104 // ============================================================
106 fh->WriteDcmExplVR(outputFileName);
107 std::cout <<"End Anonymize" << std::cout;
109 // ============================================================
110 // Remove the Anonymize list
111 // ============================================================
112 f->ClearAnonymizeList();