[Insight-users] Problem with ItkImageFileWriter

satyanarayana reddy satyajanga at gmail.com
Mon May 10 02:17:13 EDT 2010


Hi,
     I am facing a problem with ItkImageFileWriter. I am using the same code
as in example file(DicomImageReadChangeHeader.cxx) to update a dcmtag but
the tag is not getting changed in the output file. Plz help me in this..

The input to this example is one dcm file and one newly created dcm file.
I have tried to change the tag value of (0002,0000) to 192, but its not
getting modified. And the header in the output file is little different to
original input file.

After removing the comments  and doing little modifications the example code
looks like this..

#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "itkImage.h"

#include "itkMetaDataDictionary.h"

#include "itkMetaDataObject.h"

#include "itkGDCMImageIO.h"

#include <list>

#include <fstream>

int main(int argc, char* argv[])

{



 typedef signed short InputPixelType;

const unsigned int Dimension = 2;

typedef itk::Image< InputPixelType, Dimension > InputImageType;



 typedef itk::ImageFileReader< InputImageType > ReaderType;

ReaderType::Pointer reader = ReaderType::New();

reader->SetFileName( argv[1] );


 typedef itk::GDCMImageIO ImageIOType;

ImageIOType::Pointer gdcmImageIO = ImageIOType::New();

reader->SetImageIO( gdcmImageIO );


  try

{


 reader->Update();


 }

catch (itk::ExceptionObject & e)

{

std::cerr << "exception in file reader " << std::endl;

std::cerr << e.GetDescription() << std::endl;

std::cerr << e.GetLocation() << std::endl;

return EXIT_FAILURE;

}


 InputImageType::Pointer inputImage = reader->GetOutput();

typedef itk::MetaDataDictionary DictionaryType;

DictionaryType & dictionary = inputImage->GetMetaDataDictionary();


//for (int i = 3; i < argc; i+=2)

//{

std::string entryId( "0002|0000") );

std::string value( "192" );

itk::EncapsulateMetaData<std::string>( dictionary, entryId, value );

//}

std::string value1;

itk::ExposeMetaData<std::string>(dictionary,entryId,value1);


cout << value << " :: " << value1 << endl;

typedef itk::ImageFileWriter< InputImageType > Writer1Type;

 Writer1Type::Pointer writer1 = Writer1Type::New();

 writer1->SetInput( reader->GetOutput() );

writer1->SetFileName( argv[2] );

writer1->SetImageIO( gdcmImageIO );


 try

{


 writer1->Update();


 }

catch (itk::ExceptionObject & e)

{

std::cerr << "exception in file writer " << std::endl;

std::cerr << e.GetDescription() << std::endl;

std::cerr << e.GetLocation() << std::endl;

return EXIT_FAILURE;

}


  return EXIT_SUCCESS;

}




The output both value and value1 are same..

But in the file its not getting changed. i am using dcmdump to see the
header information.


Thank You,


Satya.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100510/47d9fc2c/attachment-0001.htm>


More information about the Insight-users mailing list