[Insight-users] issue with metaImageIO

Luis Ibanez luis.ibanez at kitware.com
Wed Jun 3 23:06:52 EDT 2009


Hi Ken,

The description of your problem seems to be incomplete.

Could you please start by telling us what
you are actually trying to do ?


     Thanks


        Luis


----

BTW: Please note that you don't need to connect a MetaImageIO
      to the file writer. The ImageIO factories take care of
      finding the proper ImageIO class based on the filename
      that you pass to the writer.

Also, please about the use of the expression

          "using namespace std"

it defeats the purpose of using namespaces.


----------------------------------------------------------------------------
ken wrote:
> I am facing some problems with read/write metaImages. The original raw 
> data file was overwritten by the generated raw data files even a new 
> file name was assigned to the writer. Code is below and any input will 
> be appreciated!
> 
> 
> /*=========================================================================*/
> 
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> 
> #include "itkMetaImageIO.h"
> 
> #include <iostream>
> #include <limits>
> #include <iomanip>
> #include <string>
> #include <sstream>
> #include <typeinfo>
> using namespace std;
> 
> 
> int main( int argc, char **argv ) {
> 
>     //Input and output image data directory
>     std::string inputImage = "A.mhd";
>     std::string outputHeaderName = "Output.mhd";
> 
>     //Define the pixel type and dimension for reader
>     typedef float InternalPixelType;
>     const unsigned int    Dimension=3;
>     typedef itk::Image<InternalPixelType, Dimension>    InternalImageType;
> 
>     //Define the reader
>     typedef itk::ImageFileReader<InternalImageType>  ReaderType;
>     ReaderType::Pointer reader = ReaderType::New();
>     typedef itk::MetaImageIO    MetaImageIOType;
>     MetaImageIOType::Pointer metaIO=MetaImageIOType::New();
>     reader->SetImageIO(metaIO);
>     reader->SetFileName(inputImage);
> 
>     //Update the reader
>     try
>     {
>         reader->Update();
>     }
>     catch(itk::ExceptionObject & ex_reader)
>     {
>         std::cerr << "ExceptionObject caught @ _reader !" << std::endl;
>         std::cout<<ex_reader<<std::endl;
>         return EXIT_FAILURE;
>     }
> 
> 
>     //Initialize the writer
>     typedef unsigned char    OutputPixelType;
>     typedef itk::Image<OutputPixelType, Dimension>    OutputImageType;
>     typedef itk::ImageFileWriter<OutputImageType>  WriterType;
>     WriterType::Pointer writer=WriterType::New();
>     writer->SetImageIO(metaIO);
>     writer->SetFileName(outputHeaderName);
> 
> 
>     writer->SetInput(reader->GetOutput());
> 
>     try
>     {
>         writer->Update();
>     }
>     catch( itk::ExceptionObject & ex)
>     {
>         std::cerr << "ExceptionObject caught @ _writer !" << std::endl;
>         std::cerr << ex << std::endl;
>         return EXIT_FAILURE;
>     }
> 
>     return EXIT_SUCCESS;
> }
> 
> 
> ------------------------------------------------------------------------
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list