[Insight-users] Re: Problems using MetaImage Reader and Writer

Luis Ibanez luis.ibanez@kitware.com
Tue, 11 Mar 2003 18:35:32 -0500


Hi Shilpa,

1) What version of ITK are you using  ?

2) In what platform are you running   ?
    are you using a Mac ?

--

Your code looks good...

Could you please do the following:

   replace the catch(...) statement with
   the following two catchs



    catch( itk::ExceptionObject & eee )
     {
      std::cerr << eee << std::endl;
      return -1;
     }
    catch( std::exception & see )
     {
      std::cerr << see.what() << std::endl;
      return -1;
     }



The message returned by the exception
object should help us to figure out
what's going wrong here.

Please let us know what you find
when running your program with these
changes



Thanks


Luis


--

Unless it is a really old one, you don't
need to set the ImageIO in to the ImageFileReader.



shilpa kinkar wrote:
> Hi Luis,
> 
> I am using .mhd extension only. My header file is pp37.mhd which is as 
> follows
> 
> NDims = 2
> 
> DimSize = 512 512
> 
> ElementSpacing = 0.7 0.585
> 
> Position = 0 0
> 
> ElementByteOrderMSB = True
> 
> ElementType = MET_USHORT
> 
> HeaderSize = -1
> 
> ElementDataFile = pp37.raw
> 
> I am using following code.
> 
> *********************************************************************************
> 
> // Declare a reader
>   typedef itk::ImageFileReader< ImageType > VolumeReaderType;
>   VolumeReaderType::Pointer reader = VolumeReaderType::New();
> 
>   typedef  itk::MetaImageIO MetaReaderType;
>  MetaReaderType ::Pointer  metaReader  = MetaReaderType::New();
> 
> /*  reader- <file://reader->>SetImageIO( metaReader ); */
> 
>   // Set the name of the file to read
>   reader->SetFileName( "pp37.mhd" ); // test.mhd
> 
>   // Set the image into which the results should be stored
>   ImageType::Pointer imOut = reader->GetOutput();
>  
>   // See if the file can be read - "try" otherwise program will
>   // mysteriously exit on failure in the Object factory
>   try  {  reader->Update();  }
>   catch( ... )
>     {
>     std::cout << "Problems reading file format" << std::endl;
>     return 1;
>     }
> 
> ***********************************************************************************
> 
> Here, Am I supposed to use SetIOImage ( metaReader ) ?
> 
> Exception is thrown in both cases - if I use it or if  I NOT use it. 
> Also, I am taking care that both ( .mhd and .raw ) files are in same 
> directory. So, what can be wrong in this case ? I get this error with 
> writer too.
> 
> Thanks,
> 
> Neha
> 
>  
> 
>  */Luis Ibanez <luis.ibanez@kitware.com>/* wrote:
> 
>     Hi Shilpa,
> 
>     Phillip problems in the Mac were due to a bug
>     in the Mac implementation of the fstream.fail()
>     function. This has been fixed now.
> 
>     ---
> 
>     Your problem with the MetaImage reader seems
>     to be related with the extension of the filename.
> 
>     Please let us know if you find that this is not
>     the case.
> 
>     Thanks
> 
> 
>     Luis
> 
> 
>     ---------------------------
> 
> 
>     shilpa kinkar wrote:
>      > Hi Philip,
>      >
>      > I saw your email exchanges regarding reading Raw files. Initially, I
>      > has tried the same thing as you did. Now, I am trying to use
>      > MetaImageReader. but having some problems. What I do is, I first use
>      > MetaImageImporter. Then I copy the MetaImage header .mhd file
>     created
>      > (image.mhd) into MetaImageReadWrite. Then I run the program and find
>      > test.mhd. This file does not look like the o! riginal raw file.
>      >
>      >
>      >
>      > Could you successfully read the raw file using MetaImageReadWrite
>     example ?
>      >
>      >
>      >
>      > Thanks,
>      >
>      > Neha
>      >
>      > *__*
>      >
>      > *__*
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      > Do you Yahoo!?
>      > Yahoo! Tax Center
>      > -
>      > forms, calculators, tips, and more
> 
> 
> 
> 
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Yahoo! Web Hosting <http://webhosting.yahoo.com/ps/wh3/prod/> - 
> establish your business online