ANIMA  4.0
animaODFEstimator.cxx
Go to the documentation of this file.
2 #include <itkTimeProbe.h>
3 #include <tclap/CmdLine.h>
4 
7 
8 int main(int argc, char **argv)
9 {
10  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
11 
12  TCLAP::ValueArg<std::string> inArg("i","input","List of diffusion weighted images or 4D volume",true,"","input diffusion images",cmd);
13  TCLAP::ValueArg<std::string> resArg("o","outputfile","Result ODF image",true,"","result ODF image",cmd);
14 
15  TCLAP::ValueArg<std::string> gradArg("g","gradientlist","List of gradients (text file)",true,"","list of gradients",cmd);
16  TCLAP::ValueArg<std::string> bvalArg("b","bval","input b-values (for checking single shell)",true,"","Input b-values",cmd);
17  TCLAP::ValueArg<std::string> refB0Arg("r","ref-b0","Externally estimated B0 (otherwise mean of B0s is used)",false,"","External B0 image",cmd);
18  TCLAP::SwitchArg bvalueScaleArg("B","b-no-scale","Do not scale b-values according to gradient norm",cmd);
19  TCLAP::ValueArg <int> selectedBvalArg("v","select-bval","B-value shell used to estimate ODFs (default: first one in data volume above 10)",false,-1,"b-value shell selection",cmd);
20 
21  TCLAP::ValueArg<double> lambdaArg("l","lambda","Lambda regularization parameter (see Descoteaux MRM 2007)",false,0.006,"lambda for regularization",cmd);
22  TCLAP::ValueArg<unsigned int> orderArg("k","order","Order of spherical harmonics basis",false,4,"Order of SH basis",cmd);
23 
24  TCLAP::ValueArg<double> sharpFactorArg("s","sharpenratio","Ratio for sharpening ODFs (see Descoteaux TMI 2009, default : 0.255)",false,0.255,"sharpening ratio",cmd);
25  TCLAP::SwitchArg sharpenArg("S","sharpenodf","Sharpen ODF ? (default: no)",cmd,false);
26 
27  TCLAP::ValueArg<std::string> normSphereArg("n","normalizefile","Sphere tesselation for normalization",false,"","Normalization sphere file",cmd);
28  TCLAP::SwitchArg normalizeArg("N","normalize","Normalize ODF ? (default: no)",cmd,false);
29 
30  TCLAP::SwitchArg radialArg("R","radialestimation","Use radial estimation (see Aganj et al) ? (default: no)",cmd,false);
31  TCLAP::ValueArg<double> aganjRegFactorArg("d","adr","Delta threshold for signal regularization, only use if R option activated (see Aganj et al, default : 0.001)",false,0.001,"delta signal regularization",cmd);
32 
33  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
34 
35  try
36  {
37  cmd.parse(argc,argv);
38  }
39  catch (TCLAP::ArgException& e)
40  {
41  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
42  return EXIT_FAILURE;
43  }
44 
46  typedef MainFilterType::TInputImage InputImageType;
47 
48  MainFilterType::Pointer mainFilter = MainFilterType::New();
49  mainFilter->SetLambda(lambdaArg.getValue());
50  if (orderArg.getValue() % 2 == 0)
51  mainFilter->SetLOrder(orderArg.getValue());
52  else
53  mainFilter->SetLOrder(orderArg.getValue() - 1);
54 
55  mainFilter->SetSharpen(sharpenArg.isSet());
56  if (sharpenArg.isSet())
57  mainFilter->SetSharpnessRatio(sharpFactorArg.getValue());
58 
59  mainFilter->SetUseAganjEstimation(radialArg.isSet());
60  mainFilter->SetDeltaAganjRegularization(aganjRegFactorArg.getValue());
61 
62  mainFilter->SetNormalize(normalizeArg.isSet());
63  if (normalizeArg.isSet())
64  mainFilter->SetFileNameSphereTesselation(normSphereArg.getValue());
65 
66  anima::setMultipleImageFilterInputsFromFileName<InputImageType,MainFilterType>(inArg.getValue(), mainFilter);
67 
68  if (refB0Arg.getValue() != "")
69  mainFilter->SetReferenceB0Image(anima::readImage <InputImageType> (refB0Arg.getValue()));
70 
71  typedef anima::GradientFileReader < std::vector < double >, double > GFReaderType;
72  GFReaderType gfReader;
73  gfReader.SetGradientFileName(gradArg.getValue());
74  gfReader.SetBValueBaseString(bvalArg.getValue());
75  gfReader.SetGradientIndependentNormalization(bvalueScaleArg.isSet());
76  gfReader.SetB0ValueThreshold(10);
77 
78  gfReader.Update();
79 
80  GFReaderType::GradientVectorType directions = gfReader.GetGradients();
81  GFReaderType::BValueVectorType mb = gfReader.GetBValues();
82 
83  for(unsigned int i = 0;i < directions.size();++i)
84  mainFilter->AddGradientDirection(i,directions[i]);
85 
86  mainFilter->SetBValuesList(mb);
87  mainFilter->SetBValueShellSelected(selectedBvalArg.getValue());
88 
89  itk::TimeProbe tmpTime;
90  tmpTime.Start();
91 
92  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
93  mainFilter->Update();
94 
95  tmpTime.Stop();
96 
97  std::cout << "Execution Time: " << tmpTime.GetTotal() << std::endl;
98 
99  anima::writeImage <MainFilterType::TOutputImage> (resArg.getValue(),mainFilter->GetOutput());
100 
101  return EXIT_SUCCESS;
102 }
int main(int argc, char **argv)
void SetGradientFileName(std::string fName)