DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
DWIPreprocess.cxx
Go to the documentation of this file.
1 
18 #include "itkDWIReader.h"
19 #include "itkDWIWriter.h"
20 
21 #include "utl.h"
22 #include "DWIPreprocessCLP.h"
23 
27 int
28 main (int argc, char const* argv[])
29 {
30  // GenerateCLP
31  PARSE_ARGS;
32 
33  // use float to save memory
34  typedef float FloatType;
35 
36  typedef itk::DWIReader<FloatType> DWIReaderType;
37  DWIReaderType::Pointer reader = DWIReaderType::New();
38  reader->SetConfigurationFile(_InputFile);
39  if (_MaskFileArg.isSet())
40  {
41  typedef DWIReaderType::MaskImageType MaskImageType;
42  MaskImageType::Pointer maskImage;
43  itk::ReadImage<MaskImageType>(_MaskFile, maskImage);
44  reader->SetMaskImage(maskImage);
45  }
46 
47  reader->SetShowWarnings(_WarnArg.isSet());
48  if (_DebugArg.isSet())
49  reader->DebugOn();
50  if (_NoNormalizeDWIArg.isSet())
51  reader->SetNormalizeDWI(false);
52  if (_IsVectorImageArg.isSet())
53  reader->SetIsInput4DImage(false);
54  if (_BThresholdArg.isSet())
55  reader->GetSamplingSchemeQSpace()->SetBThresholdSingleShell(_BThreshold);
56  reader->Update();
57 
58  DWIReaderType::DWIImageType::Pointer dwiImage;
59  DWIReaderType::B0ImageType::Pointer b0Image;
60  dwiImage = reader->GetOutput();
61  b0Image = reader->GetB0Image();
62 
63  if (_B0ImageFileArg.isSet())
64  itk::SaveImage(b0Image, _B0ImageFile);
65 
66  typedef itk::DWIWriter<FloatType> DWIWriterType;
67  DWIWriterType::Pointer writer = DWIWriterType::New();
68  writer->SetInput(dwiImage);
69  if (_OutputEachShellArg.isSet())
70  writer->SetOutputEachShell(true);
71  writer->SetSamplingSchemeQSpace(reader->GetSamplingSchemeQSpace());
72  writer->SetConfigurationFile(_OutputFile);
73 
74  std::string _OutputFile_ext, _OutputFile_noext;
75  utl::GetFileExtension(_OutputFile, _OutputFile_ext, _OutputFile_noext);
76  if (_BFileArg.isSet())
77  writer->SetBFile(_BFile);
78  else
79  writer->SetBFile(_OutputFile_noext + "_b." + _OutputFile_ext);
80  if (_GradFileArg.isSet())
81  writer->SetOrientationFile(_GradFile);
82  else
83  writer->SetOrientationFile(_OutputFile_noext + "_grad." + _OutputFile_ext);
84  if (_DWIFileArg.isSet())
85  writer->SetDWIFile(_DWIFile);
86  else
87  writer->SetDWIFile(_OutputFile_noext + "_dwi.nii.gz");
88 
89  writer->Update();
90 
91  return 0;
92 }
helper functions specifically used in dmritool
bool SaveImage(const SmartPointer< ImageType > &image, const std::string &filename, const std::string &printInfo="Writing Image:")
Definition: utlITK.h:157
write gradient file, b values and DWI files (with optional index file)
Definition: itkDWIWriter.h:60
Load gradient file, b values and DWI files (with optional index file)
Definition: itkDWIReader.h:59
int main(int argc, char const *argv[])
Read DWI images, gradients, b values, and output the formal normalized formalt in a configuration fil...
void GetFileExtension(const std::string &fileNameAbsolute, std::string &ext, std::string &fileNoExt)
Definition: utlCore.h:559