[Insight-users] Problems with Analyze files
David Nichols
dnichols at sourcesignal . com
Tue, 03 Jun 2003 19:05:32 -0700
I'm having trouble reading/writing Analyze files (the hdr/img style)
using the program below. I'm using InsightToolkit-1.2.0 with Visual
Studio 6.0 under Windows XP. The program executes without complaint
but the resulting output is unacceptable in at least two areas.
1) The orientation of the resulting image differs from the input
image. The input image has data_history.orient = 3 (transverse
flipped) while the output image has data_history.orient = 1 (coronal
unflipped)
2) The image data is byte-swapped.
As an itk newbie I'm sure I'm simply missing something simple, but I'm
not sure what it is. Any help would be appreciated.
Thanks,
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 );
}