ANIMA  4.0
animaT2RelaxometryEstimation.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 int main(int argc, char **argv)
11 {
12  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
13 
14  TCLAP::ValueArg<std::string> t2Arg("l","t2","List of T2 relaxometry images",true,"","T2 relaxometry images",cmd);
15  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",false,"","computation mask",cmd);
16 
17  TCLAP::ValueArg<std::string> t1MapArg("","t1","T1 map",false,"","T1 map",cmd);
18 
19  TCLAP::ValueArg<std::string> resT2Arg("o","out-t2","Result T2 image",true,"","result T2 image",cmd);
20  TCLAP::ValueArg<std::string> resM0Arg("O","out-m0","Result M0 image",false,"","result M0 image",cmd);
21 
22  TCLAP::ValueArg<double> trArg("","tr","Repetition time for T2 relaxometry (default: 5000)",false,5000,"repetition time",cmd);
23  TCLAP::ValueArg<double> upperBoundT2Arg("u","upper-bound-t2","T2 value upper bound (default: 5000)",false,5000,"T2 value upper bound",cmd);
24 
25  TCLAP::ValueArg<double> echoSpacingArg("e","echo-spacing","Spacing between two successive echoes (default: 10)",false,10,"Spacing between echoes",cmd);
26  TCLAP::ValueArg<double> backgroundSignalThresholdArg("t","signal-thr","Background signal threshold (default: 10)",false,10,"Background signal threshold",cmd);
27 
28  TCLAP::ValueArg<unsigned int> numOptimizerIterArg("","opt-iter","Maximal number of optimizer iterations (default: 2000)",false,2000,"Maximal number of optimizer iterations",cmd);
29  TCLAP::ValueArg<double> optimizerStopConditionArg("","opt-stop","Optimizer stopping threshold (default: 1.0e-4)",false,1.0e-4,"Optimizer stopping threshold",cmd);
30 
31  TCLAP::ValueArg<unsigned int> nbpArg("T","numberofthreads","Number of threads to run on (default : all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
32 
33  try
34  {
35  cmd.parse(argc,argv);
36  }
37  catch (TCLAP::ArgException& e)
38  {
39  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
40  return EXIT_FAILURE;
41  }
42 
43  typedef itk::Image <double,3> InputImageType;
44  typedef InputImageType OutputImageType;
46  typedef itk::ImageFileReader <InputImageType> InputImageReaderType;
47  typedef itk::ImageFileWriter <OutputImageType> OutputImageWriterType;
48 
49  FilterType::Pointer mainFilter = FilterType::New();
50 
51  // Read and set T2 relaxometry images
52  anima::setMultipleImageFilterInputsFromFileName<InputImageType,FilterType>(t2Arg.getValue(),mainFilter);
53 
54  mainFilter->SetTRValue(trArg.getValue());
55  mainFilter->SetEchoSpacing(echoSpacingArg.getValue());
56 
57  mainFilter->SetMaximumOptimizerIterations(numOptimizerIterArg.getValue());
58  mainFilter->SetOptimizerStopCondition(optimizerStopConditionArg.getValue());
59 
60  mainFilter->SetT2UpperBoundValue(upperBoundT2Arg.getValue());
61 
62  if (t1MapArg.getValue() != "")
63  {
64  InputImageReaderType::Pointer t1MapRead = InputImageReaderType::New();
65  t1MapRead->SetFileName(t1MapArg.getValue().c_str());
66  t1MapRead->Update();
67 
68  mainFilter->SetT1Map(t1MapRead->GetOutput());
69  }
70 
71  if (maskArg.getValue() != "")
72  {
73  typedef itk::ImageFileReader < itk::Image <unsigned char, 3> > itkMaskReader;
74  itkMaskReader::Pointer maskRead = itkMaskReader::New();
75  maskRead->SetFileName(maskArg.getValue().c_str());
76  maskRead->Update();
77 
78  mainFilter->SetComputationMask(maskRead->GetOutput());
79  }
80 
81  mainFilter->SetAverageSignalThreshold(backgroundSignalThresholdArg.getValue());
82  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
83 
84  itk::TimeProbe tmpTime;
85  tmpTime.Start();
86 
87  mainFilter->Update();
88 
89  tmpTime.Stop();
90 
91  std::cout << "Total computation time: " << tmpTime.GetTotal() << std::endl;
92 
93  OutputImageWriterType::Pointer resultT2Writer = OutputImageWriterType::New();
94  resultT2Writer->SetFileName(resT2Arg.getValue().c_str());
95  resultT2Writer->SetUseCompression(true);
96  resultT2Writer->SetInput(mainFilter->GetOutput(0));
97 
98  resultT2Writer->Update();
99 
100  if (resM0Arg.getValue() != "")
101  {
102  OutputImageWriterType::Pointer resultM0Writer = OutputImageWriterType::New();
103  resultM0Writer->SetFileName(resM0Arg.getValue().c_str());
104  resultM0Writer->SetUseCompression(true);
105  resultM0Writer->SetInput(mainFilter->GetOutput(1));
106 
107  resultM0Writer->Update();
108  }
109 
110  return EXIT_SUCCESS;
111 }
int main(int argc, char **argv)