X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=Example%2FexAnonymize.cxx;h=df651483ba04a755706f7fd9abb627d0ac68b3d8;hb=8218b27635bebfee81540217d64a9a0291248921;hp=ef1af14627128054da47618de22a96aaaf1a40ff;hpb=b3550f0f5c6881e60b6f6b981760b75b0eedf1d8;p=gdcm.git diff --git a/Example/exAnonymize.cxx b/Example/exAnonymize.cxx index ef1af146..df651483 100644 --- a/Example/exAnonymize.cxx +++ b/Example/exAnonymize.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exAnonymize.cxx,v $ Language: C++ - Date: $Date: 2005/02/06 14:56:22 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/03/02 17:19:45 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,14 +18,20 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmCommon.h" +#include "gdcmDebug.h" #include int main(int argc, char *argv[]) { - gdcm::File *f1; - + + gdcm::Debug::DebugOn(); + std::cout << "------------------------------------------------" << std::endl; + std::cout << "Anonymize a full gdcm-readable Dicom image" << std::endl; + std::cout << " Warning : probably segfaults if pixels are not " + << " gdcm readable. Use exAnonymizeNoLoad" << std::endl; + if( argc < 3 ) { std::cerr << "Usage " << argv[0] << " Source image.dcm " @@ -36,54 +42,45 @@ int main(int argc, char *argv[]) std::string fileName = argv[1]; std::string outputFileName = argv[2]; -// --------------------- we read the input image +// ============================================================ +// Read the input image. +// ============================================================ std::cout << argv[1] << std::endl; f1 = new gdcm::File( fileName ); if (!f1->IsReadable()) { - std::cerr << "Sorry, " << fileName <<" not a Readable DICOM / ACR File" + std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" <AddAnonymizeElement(0x0010, 0x0010, "Tartempion"); - // Patient's ID - f1->AddAnonymizeElement( 0x0010, 0x0020,"007" ); - // Study Instance UID - f1->AddAnonymizeElement(0x0020, 0x000d, "6.66.666.6666" ); - -// --------------------- we overwrite the file - -// No need to load the pixels. -// The gdcm::File remains untouched in memory - - f1->AnonymizeNoLoad(); - -// No need to write the File : modif were done on disc ! // ============================================================ // Load the pixels in memory. -// Write a new file // ============================================================ // We need a gdcm::FileHelper, since we want to load the pixels gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1); -// --- Don't forget to load the Pixels ... -// (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) + // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) + + uint8_t *imageData = fh1->GetImageData(); - //uint8_t *imageData= fh1->GetImageData(); - fh1->GetImageData(); + if ( imageData == 0 ) + { + std::cerr << "Sorry, Pixels of" << fileName <<" are not " + << " gdcm-readable." << std::endl + << "Use exAnonymizeNoLoad" << std::endl; + + return 0; + } +// ============================================================ +// Choose the fields to anonymize. +// ============================================================ // Institution name f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); // Patient's name @@ -94,16 +91,26 @@ int main(int argc, char *argv[]) f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" ); // Telephone f1->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + // Aware use will add new fields here + +// The gdcm::File is modified in memory f1->AnonymizeFile(); - + +// ============================================================ +// Write a new file +// ============================================================ + fh1->WriteDcmExplVR(outputFileName); + std::cout <<"End Anonymize" << std::cout; - //If we reach here everything is fine, return 0 then: - - f1->ClearAnonymizeList(); +// ============================================================ +// Remove the Anonymize list +// ============================================================ + f1->ClearAnonymizeList(); + delete f1; delete fh1; - return 0; + return 0; }