[Insight-users] Re:VectorImage IO

Bryn Lloyd blloyd at bwh.harvard.edu
Wed Aug 24 19:32:30 EDT 2005


Hi Karthik,

If I understand correctly, you say VectorImages should be readable/writable?

I think the IO does not work for VectorImages yet. I have added some
simple code to this email to read and write a VectorImage. It does not
compile!?

I want to write a test-program for Gordon to read/write Nrrd images into ITK.

Thanks!

Bryn


---------------------------
#include <fstream>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVectorImage.h"


//int itkVectorImageNrrdReadWriteTest( int ac, char* av[] )
int main( int ac, char* av[]  )
{
  if(ac < 2)
    {
    std::cerr << "Usage: " << av[0] << " Input Output\n";
    return EXIT_FAILURE;
    }

  typedef float PixelType;
  typedef itk::VectorImage<PixelType, 2> myImage;


  itk::ImageFileReader<myImage>::Pointer reader
                                  = itk::ImageFileReader<myImage>::New();
  reader->SetFileName(av[1]);

  try
    {
    reader->Update();
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file reader " << std::endl;
    std::cerr << e.GetDescription() << std::endl;
    std::cerr << e.GetLocation() << std::endl;
    return EXIT_FAILURE;
    }

  myImage::Pointer image = reader->GetOutput();
  image->Print(std::cout );

  // Generate test image
  itk::ImageFileWriter<myImage>::Pointer writer;
  writer = itk::ImageFileWriter<myImage>::New();
  writer->SetInput( reader->GetOutput() );
  writer->SetFileName(av[2]);
  try
    {
    writer->Update();
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file writer " << std::endl;
    std::cerr << e.GetDescription() << std::endl;
    std::cerr << e.GetLocation() << std::endl;
    return EXIT_FAILURE;
    }


  return EXIT_SUCCESS;

}





More information about the Insight-users mailing list