[Insight-users] Re: Re:VectorImage IO
Karthik Krishnan
Karthik.Krishnan at kitware.com
Wed Aug 24 21:31:50 EDT 2005
Hi Bryn,
On Wed, 2005-08-24 at 19:32 -0400, Bryn Lloyd wrote:
> Hi Karthik,
>
> If I understand correctly, you say VectorImages should be readable/writable?
Yes it is, with any file format that supports multi-component data such
as Metaimage, nrrd, vtk, ........
>
> 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!?
There is a test for that does IO with the VectorImage: Please take a
look at Testing/Code/Common/itkVectorImageTest.cxx.
The line you need to change to get this code to compile is:
So your code should read:
typedef itk::VectorImage< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType, itk::DefaultConvertPixelTraits<
PixelType > > ReaderType;
instead of
typedef itk::ImageFileReader< ImageType > ReaderType;
[The point being that you want the reader treating the VectorImage as a
multi-component 3 dimensional image with scalar pixels, rather than as a
3D image with Vector pixels.]
Yes I know that you may not be used to adding that extra word there, I
intend picking this up from as traits from the image itself, so you
won't have to do that in future, but I won't do that during before the
release.
Thanks
Regards
Karthik
>
> 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