[Insight-users] write out all dicom header info

Eric Claus eric.claus at colorado.edu
Fri Dec 8 16:25:51 EST 2006


Hi,
I am trying to use ITK to read in 2 different DICOM images, combine the 
images by taking the sqrt(image1^2 + image2^2) and then writing out the 
image with the header from image1.  I have been successful in reading 
and writing the images, but have been unable to figure out how to write 
the entire header.  Is there any easy way to just copy all the header 
info from one image to another?  The current program appears to only 
write out the information that is part of the MetaDictionary???  I 
pasted my code below if that is of any use to anyone.

Thanks in advance,
Eric


#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkGDCMImageIO.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"

#include <list>
#include <fstream>

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

  // Verify the number of parameters in the command line
  // Should have nonzshim, zshim, outputname
  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " nonzshimImage zshimImage outputImage\n";
    return EXIT_FAILURE;
    }

  typedef signed short InputPixelType;
  const unsigned int   InputDimension = 2;

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


  typedef itk::ImageFileReader< InputImageType > ReaderType;

  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
 
  ReaderType::Pointer reader2 = ReaderType::New();
  reader2->SetFileName( argv[2] );
  
  try
    {
    reader->Update();
    reader2->Update();
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file reader " << std::endl;
    std::cerr << e << std::endl;
    return EXIT_FAILURE;
    }


typedef itk::Image<InputPixelType, InputDimension> InputImageType;
typedef itk::ImageRegionConstIterator< InputImageType > ConstIteratorType;
typedef itk::ImageRegionIterator< InputImageType > IteratorType;


InputImageType::Pointer image = reader->GetOutput();   
ConstIteratorType constIterator1( image, image->GetRequestedRegion() );
IteratorType iterator1( image, image->GetRequestedRegion() );
   
InputImageType::Pointer image2 = reader2->GetOutput(); 
ConstIteratorType constIterator2( image2, image2->GetRequestedRegion() );
IteratorType iterator2( image2, image2->GetRequestedRegion() );


   
ConstIteratorType in1( image, image->GetRequestedRegion() );
ConstIteratorType in2( image2, image2->GetRequestedRegion() );

IteratorType out( image2, image->GetRequestedRegion() );

for ( in1.GoToBegin(), out.GoToBegin(), in2.GoToBegin(); !in1.IsAtEnd(); 
++in1, ++out, ++in2 )
{
out.Set( 0.5 + (1.33 * sqrt( (in1.Get()) * (in1.Get()) + (in2.Get()) * 
(in2.Get()) )));
}

 typedef itk::ImageFileWriter< InputImageType >  Writer1Type;

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

  writer1->SetFileName( argv[3] );
  writer1->SetInput( image2 );

  try
    {
    writer1->Update();
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file writer " << std::endl;
    std::cerr << e << std::endl;
    return EXIT_FAILURE;
    }
 
    return EXIT_SUCCESS;

}


-- 
Eric Claus
Department of Psychology
University of Colorado at Boulder




More information about the Insight-users mailing list