[Insight-developers] writing meta files

Damion Shelton beowulf@cs.cmu.edu
Fri, 25 Apr 2003 17:32:40 -0400


Hi,

> - Please send me the text lines at the top of your output metaFile.

ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = True
DimSize = 181 217 180
ElementType = MET_UCHAR
ElementDataFile = LOCAL

> - Please verify that all of the data is being writen (is the output 
> file of the expected size with the additional text header?).

Hmmmm... the file sizes are (input first, output second):

-rw-r--r--   1 beowulf  staff     7109137 Nov  3  2001 
brainweb165a10f17.raw
-rw-r--r--   1 beowulf  staff     7070007 Apr 25 17:22 mynewfile.mha

Looks like the output file is smaller.

> - Do you get any error messages before the program dies?

Opening file with name: /Users/beowulf/brainweb/Brain/mynewfile.mha
NDims required and not defined.
MetaObject: Read: MET_Read Failed
MetaImage: M_Read: Error parsing file
MetaImage: Read: Cannot parse file
Abort trap

I'm calling the output file extension .mha - does the reader expect a 
different extension if it's being written as a single file?

Thanks for the help,
-Damion-

Incidentally, the code for the writer is as follows:

   // Some typedefs
   typedef itk::Image<unsigned char, 3> ImageType;
   typedef itk::ImageFileReader<ImageType> ImageFileReaderType;
   typedef itk::ImageFileWriter<ImageType> ImageFileWriterType;

   // Read the file
   ImageFileReaderType::Pointer m_ImageReader;
   m_ImageReader = ImageFileReaderType::New();
   itk::MetaImageIOFactory::RegisterOneFactory();

   m_ImageReader->SetFileName( 
"/Users/beowulf/brainweb/Brain/brainweb165a10f17.mha" );
   m_ImageReader->Update();

   // Ok, now that we've read the file let's write it back
   ImageFileWriterType::Pointer m_ImageWriter;
   m_ImageWriter = ImageFileWriterType::New();
   m_ImageWriter->SetInput( m_ImageReader->GetOutput() );
   itk::MetaImageIOFactory::RegisterOneFactory();

   m_ImageWriter->SetFileName( 
"/Users/beowulf/brainweb/Brain/mynewfile.mha" );
   m_ImageWriter->Update();

---------
Damion Shelton
Graduate Student
Carnegie Mellon University, Robotics Institute
A408-o Newell Simon Hall
Pittsburgh PA 15213
412.268.3866 (office)
412.818.8829 (cell)
http://www.cs.cmu.edu/~beowulf
---------
Today's words of wisdom...
If you define cowardice as running away at the first sign of danger, 
screaming and tripping and begging for mercy, then yes, Mr. Brave man, 
I guess I'm a coward.