ANIMA  4.0
animaT2EPGRelaxometryEstimation.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <tclap/CmdLine.h>
3 
4 #include <itkImageFileReader.h>
5 #include <itkImageFileWriter.h>
8 #include <itkTimeProbe.h>
9 
10 //Update progression of the process
11 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
12 {
13  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
14  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
15 }
16 
17 int main(int argc, char **argv)
18 {
19  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
20 
21  TCLAP::ValueArg<std::string> t2Arg("l","t2","List of T2 relaxometry images",true,"","T2 relaxometry images",cmd);
22  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",false,"","computation mask",cmd);
23 
24  TCLAP::ValueArg<std::string> t1MapArg("","t1","T1 map",false,"","T1 map",cmd);
25 
26  TCLAP::ValueArg<std::string> resT2Arg("o","out-t2","Result T2 image",true,"","result T2 image",cmd);
27  TCLAP::ValueArg<std::string> resM0Arg("O","out-m0","Result M0 image",false,"","result M0 image",cmd);
28  TCLAP::ValueArg<std::string> resB1Arg("","out-b1","B1 map",false,"","B1 map",cmd);
29 
30  TCLAP::ValueArg<double> trArg("","tr","Repetition time for T2 relaxometry (default: 5000)",false,5000,"repetition time",cmd);
31  TCLAP::ValueArg<double> upperBoundT2Arg("u","upper-bound-t2","T2 value upper bound (default: 5000)",false,5000,"T2 value upper bound",cmd);
32 
33  TCLAP::ValueArg<double> echoSpacingArg("e","echo-spacing","Spacing between two successive echoes (default: 10)",false,10,"Spacing between echoes",cmd);
34  TCLAP::ValueArg<double> excitationT2FlipAngleArg("","t2-ex-flip","Excitation flip angle for T2 (in degrees, default: 90)",false,90,"T2 excitation flip angle",cmd);
35  TCLAP::ValueArg<double> t2FlipAngleArg("","t2-flip","All flip angles for T2 (in degrees, default: 180)",false,180,"T2 flip angle",cmd);
36  TCLAP::ValueArg<double> backgroundSignalThresholdArg("t","signal-thr","Background signal threshold (default: 10)",false,10,"Background signal threshold",cmd);
37 
38  TCLAP::ValueArg<unsigned int> nbpArg("T","numberofthreads","Number of threads to run on (default : all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
39 
40  TCLAP::ValueArg<unsigned int> numOptimizerIterArg("","opt-iter","Maximal number of optimizer iterations (default: 2000)",false,2000,"Maximal number of optimizer iterations",cmd);
41  TCLAP::ValueArg<double> optimizerStopConditionArg("","opt-stop","Optimizer stopping threshold (default: 1.0e-4)",false,1.0e-4,"Optimizer stopping threshold",cmd);
42 
43  try
44  {
45  cmd.parse(argc,argv);
46  }
47  catch (TCLAP::ArgException& e)
48  {
49  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
50  return EXIT_FAILURE;
51  }
52 
53  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
54  callback->SetCallback(eventCallback);
55 
56  typedef itk::Image <double,3> InputImageType;
57  typedef InputImageType OutputImageType;
59 
60  FilterType::Pointer mainFilter = FilterType::New();
61 
62  // Read and set T2 relaxometry images
63  unsigned int numInputs = anima::setMultipleImageFilterInputsFromFileName<InputImageType,FilterType>(t2Arg.getValue(),mainFilter);
64 
65  mainFilter->SetEchoSpacing(echoSpacingArg.getValue());
66  mainFilter->SetT2FlipAngles(t2FlipAngleArg.getValue() * M_PI / 180.0,numInputs);
67  mainFilter->SetT2ExcitationFlipAngle(excitationT2FlipAngleArg.getValue() * M_PI / 180.0);
68 
69  mainFilter->SetT2UpperBound(upperBoundT2Arg.getValue());
70  mainFilter->SetTRValue(trArg.getValue());
71 
72  mainFilter->SetMaximumOptimizerIterations(numOptimizerIterArg.getValue());
73  mainFilter->SetOptimizerStopCondition(optimizerStopConditionArg.getValue());
74 
75  if (t1MapArg.getValue() != "")
76  mainFilter->SetT1Map(anima::readImage <InputImageType> (t1MapArg.getValue()));
77 
78  if (maskArg.getValue() != "")
79  mainFilter->SetComputationMask(anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
80 
81  mainFilter->SetAverageSignalThreshold(backgroundSignalThresholdArg.getValue());
82  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
83 
84  itk::TimeProbe tmpTime;
85  tmpTime.Start();
86 
87  mainFilter->AddObserver(itk::ProgressEvent(), callback);
88  mainFilter->Update();
89 
90  tmpTime.Stop();
91 
92  std::cout << "\nTotal computation time: " << tmpTime.GetTotal() << std::endl;
93 
94  anima::writeImage <OutputImageType> (resT2Arg.getValue(),mainFilter->GetOutput(0));
95 
96  if (resM0Arg.getValue() != "")
97  anima::writeImage <OutputImageType> (resM0Arg.getValue(),mainFilter->GetOutput(1));
98 
99  if (resB1Arg.getValue() != "")
100  anima::writeImage <OutputImageType> (resB1Arg.getValue(),mainFilter->GetOutput(2));
101 
102  return EXIT_SUCCESS;
103 }
int main(int argc, char **argv)
itk::SmartPointer< ImageType > readImage(std::string filename)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)