DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
VectorImageNormalization.cxx
Go to the documentation of this file.
1 
18 #include "utlITK.h"
19 
20 #include "VectorImageNormalizationCLP.h"
21 
25 
31 int
32 main (int argc, char const* argv[])
33 {
34  // GenerateCLP
35  PARSE_ARGS;
36 
37  utlGlobalException(_NormalizationType=="NONE", "need to set --type");
38 
39  typedef float PixelType;
40  bool isSparseImage = itk::IsSparseImage(_InputFile);
41 
42  if (isSparseImage)
43  {
46 
47  InputImageType::Pointer input = InputImageType::New();
48  OutputImageType::Pointer output = OutputImageType::New();
51 
52  itk::ReadImage<InputImageType, ReaderType>(_InputFile, input);
53 
55  FilterType::Pointer filter = FilterType::New();
56 
57  filter->SetInput(input);
58  if (_NormalizationType=="SUM")
59  filter->SetNormalizeType(FilterType::FunctorType::SUM);
60  else if (_NormalizationType=="L1NORM")
61  filter->SetNormalizeType(FilterType::FunctorType::L1NORM);
62  else if (_NormalizationType=="L2NORM")
63  filter->SetNormalizeType(FilterType::FunctorType::L2NORM);
64 
65  // NOTE: SparseVectorImage only works for single thread
66  filter->SetNumberOfThreads(1);
67  filter->Update();
68 
69  output = filter->GetOutput();
70 
71  itk::SaveImage<OutputImageType, WriterType>(output, _OutputFile);
72  }
73  else
74  {
75  typedef itk::VectorImage<PixelType, 3> InputImageType;
76  typedef itk::VectorImage<PixelType, 3> OutputImageType;
77 
78  InputImageType::Pointer input = InputImageType::New();
79  OutputImageType::Pointer output = OutputImageType::New();
80 
81  itk::ReadImage(_InputFile, input);
82 
84  FilterType::Pointer filter = FilterType::New();
85 
86  filter->SetInput(input);
87  if (_NormalizationType=="SUM")
88  filter->SetNormalizeType(FilterType::FunctorType::SUM);
89  else if (_NormalizationType=="L1NORM")
90  filter->SetNormalizeType(FilterType::FunctorType::L1NORM);
91  else if (_NormalizationType=="L2NORM")
92  filter->SetNormalizeType(FilterType::FunctorType::L2NORM);
93 
94  filter->Update();
95 
96  output = filter->GetOutput();
97 
98  itk::SaveImage(output, _OutputFile);
99  }
100 
101  return 0;
102 }
int main(int argc, char const *argv[])
Normalize each voxel in a VectorImage or SparseVectorImage.
bool SaveImage(const SmartPointer< ImageType > &image, const std::string &filename, const std::string &printInfo="Writing Image:")
Definition: utlITK.h:157
bool IsSparseImage(const std::string &filename)
Definition: utlITK.h:426
Writes sparse vector image data to key and value files.
Pixel-wise vector normalization.
bool ReadImage(const std::string &filename, SmartPointer< ImageType > &image, const std::string &printInfo="Reading Image:")
Definition: utlITK.h:110
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
An n-dimensional vector image with a sparse memory model.