[Insight-developers] writing meta files

Stephen R. Aylward aylward@unc.edu
Mon, 28 Apr 2003 13:06:09 -0400


Hi Damion,

I just recompiled itk and its apps, Ran the MetaImageReadWrite demo 
which does the same that you are doing, and created a file close to 
yours, and despite my attempts, I cannot reproduce the error that you 
are having.   I've tried adding spaces and control characters after the 
word Image on the first line, etc.   I cannot determine why it is 
reporting NDims being not defined in your application.

Perhaps there is a memory issue - if both files should be of the same 
size, and the raw file on the second one is smaller, there seems to be 
some level of corruption.    Can you send me a snipit of the code 
causing this problem?   What system are you running on?

Thanks - sorry for the problems,
Stephen

Damion Shelton wrote:
> 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.
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers


-- 
===============================================
Dr. Stephen R. Aylward
Assistant Professor of Radiology
Adjunct Assistant Professor of Computer Science
http://caddlab.rad.unc.edu
aylward@unc.edu
(919) 966-9695