[Insight-users] Problems with Analyze files

David Nichols dnichols at sourcesignal . com
Thu, 19 Jun 2003 16:43:32 -0700


I'm having trouble reading analyze images with itk (Version 1.2.0, the
standard release on the website, compiled with Visual C++ 6.0, running
Windows XP).  The program below seems as if it should simply copy the
input file to the output file, but this doesn't happen.  With the
program below, if I feed it an Analyze file with 16-bit input the
output is byte-swapped.  If I change the data type to float (using
typedef float PixelType;) and provide as input a 32 bit floating point
set of images the output voxels are all zero.  I can read both of the
input files with MRIcro, so they seem to be correct.  Does anyone have
any ideas how to fix this?  Alternatively, is there another way to
read in 3D data?

I'd like to register two data sets, but I'd have no confidence in the
results if I have no confidence that the image data is being read
correctly.  My initial attempt (using the "Hello world registration"
from the users guide and changing the dimension from 2 to 3) was
unimpressive, terminating after 14 iterations with an optimized value
of about 1.0e6 and producing an output image (the transformed moving
image) looked like hash.

Thanks for any advice,

David Nichols
Source Signal Imaging
dnichols at sourcesignal . com

============================================================

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"

// Define input image characteristics
typedef short int PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension> ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;

int
main(int argc, char *argv[])
{
  if( argc < 3 ){
    std::cerr << "Usage : TestReadWriteAnalyze InFile OutFile\n";
    return( -2 );
  }
  // Instantiate reader and writer
  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  // Hook up file names
  reader->SetFileName( argv[1]);
  writer->SetFileName( argv[2]);
  // Connect reader and writer
  writer->SetInput( reader->GetOutput() );
  // Ready to roll
  try {
    writer->Update();
  } catch( itk::ExceptionObject &err ){
    std::cerr << "Exception object caught!" << std::endl;
    std::cerr << err << std::endl;
    return( -1 );
  }
  return( 1 );
}