[Insight-users] Simple question on raw file reading
Phillip Cheng
pmcheng@u.washington.edu
Mon, 3 Mar 2003 15:57:01 -0800
Hello,
I'm new to ITK and am trying to read in a simple raw image volume, but
I'm not sure what I'm doing wrong. I'm running the current ITK CVS on
Mac OS X 10.2.4. Here's a sample:
====================================================
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRawImageIO.h"
int main()
{
typedef itk::Image<float,3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader=ReaderType::New();
typedef itk::RawImageIO<float,3> ImageIOType;
ImageIOType::Pointer rawImageIO=ImageIOType::New();
reader->SetImageIO(rawImageIO);
reader->SetFileName("pet.img");
rawImageIO->SetByteOrderToBigEndian();
rawImageIO->SetFileTypeToBinary();
rawImageIO->SetFileDimensionality(3);
rawImageIO->SetOrigin(0,0.0);
rawImageIO->SetOrigin(1,0.0);
rawImageIO->SetOrigin(2,0.0);
rawImageIO->SetDimensions(0,128);
rawImageIO->SetDimensions(1,128);
rawImageIO->SetDimensions(2,36);
rawImageIO->SetSpacing(0,4.3);
rawImageIO->SetSpacing(1,4.3);
rawImageIO->SetSpacing(2,4.25);
try
{
reader->Update();
}
catch(itk::ExceptionObject& err)
{
std::cout << "Error: "<< err << std::endl;
}
}
============================================
When I run this, I get the following message:
Error:
itk::ExceptionObject (0x1c6230)
Location: "Unknown"
File: /Users/pmcheng/ITK/Insight/Code/IO/itkRawImageIO.txx
Line: 190
Description: itk::ERROR: RawImageIO(0x1c4070): Read failed: Wanted
2359296 bytes, but read 2359296 bytes.
I'm not sure what this error means. The file "pet.img" that I'm trying
to load is exactly 2359296 bytes and is a big-endian 128x128x36
floating point array.
Thanks for any help.
Phillip Cheng