DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
TensorFormatConverter.cxx
Go to the documentation of this file.
1 
11 #include "TensorFormatConverterCLP.h"
12 #include "itkImageRegionIteratorWithIndex.h"
13 #include "utl.h"
14 
18 int
19 main (int argc, char const* argv[])
20 {
21  // GenerateCLP
22  PARSE_ARGS;
23 
24  utlGlobalException(_InputFormat==_OutputFormat, "input format == output format");
25 
26  typedef itk::VectorImage<double,3> ImageType;
27  ImageType::Pointer inputImage = ImageType::New();
28  itk::ReadVectorImage(_InputFile, inputImage);
29 
30  ImageType::Pointer outputImage = ImageType::New();
31  itk::CopyImageInformation(inputImage, outputImage);
32  int outDim = 6;
33  if (_OutputFormat=="9D")
34  outDim=9;
35  else
36  outDim=6;
37  outputImage->SetNumberOfComponentsPerPixel(outDim);
38  outputImage->Allocate();
39 
40  itk::ImageRegionConstIteratorWithIndex<ImageType> itInput(inputImage, inputImage->GetLargestPossibleRegion());
41  itk::ImageRegionIteratorWithIndex<ImageType> itOutput(outputImage, outputImage->GetLargestPossibleRegion());
42 
43  utl::Vector<double> inputVec;
44  utl::Matrix<double> tensor;
45 
46  ImageType::PixelType inputPixel, outputPixel(outDim);
47  for (itInput.GoToBegin(), itOutput.GoToBegin();
48  !itInput.IsAtEnd();
49  ++itInput, ++itOutput)
50  {
51  inputPixel = itInput.Get();
52 
53  if (_InputFormat=="9D" && _OutputFormat=="6D_UPPER")
54  utl::ConvertTensor9DTo6D(inputPixel, outputPixel, TENSOR_UPPER_TRIANGULAR);
55  else if (_InputFormat=="6D_UPPER" && _OutputFormat=="9D")
56  utl::ConvertTensor6DTo9D(inputPixel, outputPixel, TENSOR_UPPER_TRIANGULAR);
57 
58  else if (_InputFormat=="6D_EMBED" && _OutputFormat=="6D_UPPER")
60  else if (_InputFormat=="6D_UPPER" && _OutputFormat=="6D_EMBED")
62 
63  else if (_InputFormat=="6D_UPPER" && _OutputFormat=="6D_LOWER")
65  else if (_InputFormat=="6D_LOWER" && _OutputFormat=="6D_UPPER")
67 
68  else if (_InputFormat=="6D_DIAGONAL_FIRST" && _OutputFormat=="6D_LOWER")
70  else if (_InputFormat=="6D_LOWER" && _OutputFormat=="6D_DIAGONAL_FIRST")
72 
73  else if (_InputFormat=="6D_DIAGONAL_FIRST" && _OutputFormat=="6D_UPPER")
75  else if (_InputFormat=="6D_UPPER" && _OutputFormat=="6D_DIAGONAL_FIRST")
77 
78  else
79  utlGlobalException(true, "TODO");
80 
81  itOutput.Set(outputPixel);
82  }
83 
84  itk::SaveImage(outputImage, _OutputFile);
85 
86  return 0;
87 }
NDArray<T,1> is a vector class which uses blas mkl.
Definition: utlVector.h:36
helper functions specifically used in dmritool
int main(int argc, char const *argv[])
Convert different tensor format.
void ReadVectorImage(const std::string &filename, SmartPointer< VectorImage< PixelType, 3 > > &image, const std::string &printInfo="Reading Image:")
Definition: utl.h:66
NDArray<T,2> is a row-major matrix.
Definition: utlMatrix.h:37
bool SaveImage(const SmartPointer< ImageType > &image, const std::string &filename, const std::string &printInfo="Writing Image:")
Definition: utlITK.h:157
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
Definition: utlITK.h:552
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
void ConvertTensor6DTo9D(const V1Type &v6d, V2Type &v9d, int v6dStoreWay)
Definition: utlDMRI.h:257
void ConvertTensor6DTo6D(const V1Type &v6d1, V2Type &v6d2, int s1, int s2)
Definition: utlDMRI.h:359
void ConvertTensor9DTo6D(const V1Type &v9d, V2Type &v6d, int v6dStoreWay)
Definition: utlDMRI.h:315