1 /*=========================================================================
4 Module: $RCSfile: exAnonymize.cxx,v $
6 Date: $Date: 2005/03/02 17:19:45 $
7 Version: $Revision: 1.3 $
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[])
29 gdcm::Debug::DebugOn();
30 std::cout << "------------------------------------------------" << std::endl;
31 std::cout << "Anonymize a full gdcm-readable Dicom image" << std::endl;
32 std::cout << " Warning : probably segfaults if pixels are not "
33 << " gdcm readable. Use exAnonymizeNoLoad" << std::endl;
37 std::cerr << "Usage " << argv[0] << " Source image.dcm "
38 << " Output image.dcm " << std::endl;
42 std::string fileName = argv[1];
43 std::string outputFileName = argv[2];
45 // ============================================================
46 // Read the input image.
47 // ============================================================
49 std::cout << argv[1] << std::endl;
51 f1 = new gdcm::File( fileName );
52 if (!f1->IsReadable()) {
53 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
58 std::cout << " ... is readable " << std::endl;
61 // ============================================================
62 // Load the pixels in memory.
63 // ============================================================
65 // We need a gdcm::FileHelper, since we want to load the pixels
66 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
68 // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one)
70 uint8_t *imageData = fh1->GetImageData();
74 std::cerr << "Sorry, Pixels of" << fileName <<" are not "
75 << " gdcm-readable." << std::endl
76 << "Use exAnonymizeNoLoad" << std::endl;
81 // ============================================================
82 // Choose the fields to anonymize.
83 // ============================================================
85 f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo");
87 f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");
89 f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );
91 f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
93 f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
94 // Aware use will add new fields here
96 // The gdcm::File is modified in memory
100 // ============================================================
102 // ============================================================
104 fh1->WriteDcmExplVR(outputFileName);
105 std::cout <<"End Anonymize" << std::cout;
107 // ============================================================
108 // Remove the Anonymize list
109 // ============================================================
110 f1->ClearAnonymizeList();