1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "gdcmFileAnonymizer.h"
#include "gdcmReader.h"
#include "gdcmWriter.h"
int main(int argc, char *argv[])
{
if( argc < 3 ) return 1;
const char* filename = argv[1];
const char* outfilename = argv[2];
//gdcm::Trace::DebugOn();
// Remove Pixel Data element:
gdcm::FileAnonymizer fa;
fa.SetInputFileName( filename );
fa.SetOutputFileName( outfilename );
fa.Empty( gdcm::Tag(0x7fe0,0x10) );
// cannot replace in-place DICOM header:
//fa.Replace( gdcm::Tag(0x2,0x2), "1.2.840.10008.5.1.4.1.1.7" );
if( !fa.Write() )
{
std::cerr << "impossible to remove Pixel Data attribute" << std::endl;
return 1;
}
// Update the DICOM Header:
gdcm::Reader reader;
reader.SetFileName( outfilename );
if( !reader.Read() )
{
std::cerr << "could not read back" << std::endl;
return 1;
}
gdcm::File & file = reader.GetFile();
gdcm::FileMetaInformation &fmi = file.GetHeader();
gdcm::TransferSyntax ts = gdcm::TransferSyntax::ImplicitVRLittleEndian;
ts = gdcm::TransferSyntax::ExplicitVRLittleEndian;
fmi.SetDataSetTransferSyntax(ts);
gdcm::Writer writer;
writer.SetFile( file );
writer.SetFileName( outfilename ); // warning overwrite file !
if( !writer.Write() )
{
std::cerr << "could not write back" << std::endl;
return 1;
}
return 0;
}
|