]> Creatis software - gdcm.git/blob - Example/exAnonymize.cxx
Update exAnonymise.cxx
[gdcm.git] / Example / exAnonymize.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exAnonymize.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/08 17:58:21 $
7   Version:   $Revision: 1.2 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmFile.h"
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
22
23 #include <iostream>
24
25 int main(int argc, char *argv[])
26 {  
27    gdcm::File *f1;
28  
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 : probabely segfaults if pixels are not "
33           << " gdcm readable. Use exAnonymizeNoLoad"            << std::endl;
34
35    if( argc < 3 )
36     {
37     std::cerr << "Usage " << argv[0] << " Source image.dcm  " 
38               << " Output image.dcm " << std::endl;
39     return 1;
40     }
41
42    std::string fileName       = argv[1];
43    std::string outputFileName = argv[2];
44
45 // ============================================================
46 //   Read the input image.
47 // ============================================================
48
49    std::cout << argv[1] << std::endl;
50
51    f1 = new gdcm::File( fileName );
52    if (!f1->IsReadable()) {
53        std::cerr << "Sorry, " << fileName <<"  not a gdcm-readable "
54            << "DICOM / ACR File"
55                  <<std::endl;
56        return 0;
57    }
58    std::cout << " ... is readable " << std::endl;
59
60
61 // ============================================================
62 //   Load the pixels in memory.
63 // ============================================================
64
65    // We need a gdcm::FileHelper, since we want to load the pixels        
66    gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
67
68    // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) 
69
70    uint8_t *imageData = fh1->GetImageData();
71
72    if ( imageData == 0 )
73    {
74        std::cerr << "Sorry, Pixels of" << fileName <<"  are not "
75            << " gdcm-readable."       << std::endl
76                  << "Use exAnonymizeNoLoad" << std::endl;
77   
78        return 0;
79    } 
80
81 // ============================================================
82 //  Choose the fields to anonymize.
83 // ============================================================
84    // Institution name 
85    f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); 
86    // Patient's name 
87    f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");   
88    // Patient's ID
89    f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );   
90    // Study Instance UID
91    f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
92    // Telephone
93    f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
94   // Aware use will add new fields here
95
96 // The gdcm::File is modified in memory
97
98    f1->AnonymizeFile();
99
100 // ============================================================
101 //   Write a new file
102 // ============================================================
103
104    fh1->WriteDcmExplVR(outputFileName);
105    std::cout <<"End Anonymize" << std::cout;
106
107 // ============================================================
108 //   Remove the Anonymize list
109 // ============================================================  
110    f1->ClearAnonymizeList();
111     
112    delete f1;
113    delete fh1; 
114    return 0;
115 }
116