DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
4DToVectorImageConverter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: 4D Image to Vector Image Converter
4 
5  Copyright (c) Pew-Thian Yap. All rights reserved.
6  See http://www.unc.edu/~ptyap/ for details.
7 
8  This software is distributed WITHOUT ANY WARRANTY; without even
9  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  PURPOSE. See the above copyright notices for more information.
11 
12  =========================================================================*/
13 
14 #include <iostream>
15 #include <string.h>
16 #include <stdio.h>
17 #include "itkImage.h"
18 #include "itkImageFileWriter.h"
19 #include "itkImageFileReader.h"
21 #include "itkImageIOBase.h"
22 #include "4DToVectorImageConverterCLP.h"
24 
25 
26 int
27 main(int argc, char *argv[])
28 {
29  PARSE_ARGS;
30 
31  // Define Variables
32  // typedef float PixelType;
33  typedef double PixelType;
34  typedef itk::VectorImage<PixelType, 3> VectorImageType;
35  typedef itk::Image<PixelType, 4> MultiVolumeImageType;
36  typedef itk::ImageFileReader<MultiVolumeImageType> ReaderType;
38 
39  MultiVolumeImageType::Pointer inputImage;
40  VectorImageType::Pointer outputImage = VectorImageType::New();
41  WriterType::Pointer writer = WriterType::New();
42  ReaderType::Pointer reader = ReaderType::New();
43 
44  reader->SetFileName(_InputFile);
45  try
46  {
47  std::cout << "Reading file: " << _InputFile << std::endl;
48  reader->Update();
49  }
50  catch (itk::ExceptionObject & err)
51  {
52  std::cerr << "ExceptionObject caught!" << std::endl;
53  std::cerr << err << std::endl;
54  return EXIT_FAILURE;
55  }
56 
57  inputImage = reader->GetOutput();
58 
60  ConvertorType::Pointer convertor = ConvertorType::New();
61  convertor->SetInput(inputImage);
62  outputImage = convertor->GetOutput();
63  convertor->Update();
64 
65  // Write Output
66  reader->UpdateOutputInformation();
67  itk::ImageIOBase::Pointer inputImageIOBase = reader->GetImageIO();
68  inputImageIOBase->ReadImageInformation();
69  itk::ImageIOBase::IOComponentType inputComponentType =
70  inputImageIOBase->GetComponentType();
71 
72  try
73  {
74  std::cout << "Writing file: " << _OutputFile << std::endl;
75  writer->SetFileName( _OutputFile );
76  writer->SetInput( outputImage );
77  writer->SetComponentType( inputComponentType );
78  writer->Update();
79  }
80  catch ( itk::ExceptionObject & err )
81  {
82  std::cerr << "ExceptionObject caught!" << std::endl;
83  std::cerr << err << std::endl;
84  return EXIT_FAILURE;
85  }
86 
87  return EXIT_SUCCESS;
88 }
89 
Writes image data, after casting, to a single file.
int main(int argc, char *argv[])
convert Image<TInputPixelType, VImageDimension+1> to VectorImage<TOutputPixelType, VImageDimension>
itk::VectorImage< ScalarType, 3 > VectorImageType
Definition: 4DImageMath.cxx:30