ANIMA  4.0
animaGammaMixtureT2RelaxometryEstimation.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 #include <boost/lexical_cast.hpp>
11 #include <boost/algorithm/string.hpp>
12 
13 #include <itkCommand.h>
14 
15 //Update progression of the process
16 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
17 {
18  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
19  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
20 }
21 
22 int main(int argc, char **argv)
23 {
24  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
25 
26  TCLAP::ValueArg<std::string> t2Arg("i","t2","T2 relaxometry images (list or 4D volume)",true,"","T2 relaxometry images",cmd);
27  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",false,"","computation mask",cmd);
28 
29  TCLAP::ValueArg<std::string> t1MapArg("","t1","T1 map",false,"","T1 map",cmd);
30  TCLAP::SwitchArg constrainArg("C","constrain","Constrain estimation of means to just the central one",cmd);
31 
32  TCLAP::ValueArg<std::string> resWeightsArg("O","out-weights","Result weights image",false,"","result weights image",cmd);
33  TCLAP::ValueArg<std::string> resM0Arg("","out-m0","Result M0 image",false,"","result M0 image",cmd);
34  TCLAP::ValueArg<std::string> resMWFArg("o","out-mwf","Result MWF image",true,"","result MWF image",cmd);
35  TCLAP::ValueArg<std::string> resB1Arg("","out-b1","Result B1 image",false,"","result B1 image",cmd);
36  TCLAP::ValueArg<std::string> resSigmaSqArg("","out-sig","Result sigma square image",false,"","result sigma square image",cmd);
37  TCLAP::ValueArg<std::string> resMeanParamArg("","mean-param","Result mean parameter image",false,"","result mean parameter image",cmd);
38 
39  TCLAP::ValueArg<double> echoSpacingArg("e","echo-spacing","Spacing between two successive echoes (default: 10)",false,10,"Spacing between echoes",cmd);
40  TCLAP::ValueArg<double> excitationT2FlipAngleArg("","t2-ex-flip","Excitation flip angle for T2 (in degrees, default: 90)",false,90,"T2 excitation flip angle",cmd);
41  TCLAP::ValueArg<double> t2FlipAngleArg("","t2-flip","All flip angles for T2 (in degrees, default: 180)",false,180,"T2 flip angle",cmd);
42  TCLAP::ValueArg<double> backgroundSignalThresholdArg("t","signal-thr","Background signal threshold (default: 10)",false,10,"Background signal threshold",cmd);
43 
44  TCLAP::ValueArg<double> gammaToleranceApproxArg("","g-tol","Gamma approximation tolerance (default: 1.0e-8)",false,1.0e-8,"Gamma approximation tolerance",cmd);
45 
46  TCLAP::ValueArg<unsigned int> nbpArg("T","numberofthreads","Number of threads to run on (default : all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
47 
48  try
49  {
50  cmd.parse(argc,argv);
51  }
52  catch (TCLAP::ArgException& e)
53  {
54  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
55  return EXIT_FAILURE;
56  }
57 
58  typedef itk::Image <double,3> InputImageType;
59  typedef InputImageType OutputImageType;
61  typedef FilterType::OutputImageType OutputImageType;
62  typedef FilterType::VectorOutputImageType VectorOutputImageType;
63  typedef itk::ImageFileReader <InputImageType> InputImageReaderType;
64 
65  FilterType::Pointer mainFilter = FilterType::New();
66 
67  unsigned int numInputs = anima::setMultipleImageFilterInputsFromFileName<InputImageType,FilterType>(t2Arg.getValue(),mainFilter);
68 
69  mainFilter->SetEchoSpacing(echoSpacingArg.getValue());
70  mainFilter->SetT2FlipAngles(t2FlipAngleArg.getValue() * M_PI / 180.0,numInputs);
71  mainFilter->SetT2ExcitationFlipAngle(excitationT2FlipAngleArg.getValue() * M_PI / 180.0);
72 
73  mainFilter->SetGammaIntegralTolerance(gammaToleranceApproxArg.getValue());
74  mainFilter->SetConstrainedParameters(constrainArg.isSet());
75 
76  if (t1MapArg.getValue() != "")
77  {
78  InputImageReaderType::Pointer t1MapRead = InputImageReaderType::New();
79  t1MapRead->SetFileName(t1MapArg.getValue().c_str());
80  t1MapRead->Update();
81 
82  mainFilter->SetT1Map(t1MapRead->GetOutput());
83  }
84 
85  if (maskArg.getValue() != "")
86  {
87  typedef itk::ImageFileReader < itk::Image <unsigned char, 3> > itkMaskReader;
88  itkMaskReader::Pointer maskRead = itkMaskReader::New();
89  maskRead->SetFileName(maskArg.getValue().c_str());
90  maskRead->Update();
91 
92  mainFilter->SetComputationMask(maskRead->GetOutput());
93  }
94 
95  mainFilter->SetAverageSignalThreshold(backgroundSignalThresholdArg.getValue());
96  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
97 
98  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
99  callback->SetCallback(eventCallback);
100  mainFilter->AddObserver(itk::ProgressEvent(), callback );
101 
102  itk::TimeProbe tmpTime;
103  tmpTime.Start();
104 
105  try
106  {
107  mainFilter->Update();
108  }
109  catch (itk::ExceptionObject &e)
110  {
111  std::cerr << e << std::endl;
112  }
113 
114  tmpTime.Stop();
115 
116  std::cout << "Estimation computation time: " << tmpTime.GetTotal() << std::endl;
117 
118  anima::writeImage<OutputImageType> (resMWFArg.getValue(),mainFilter->GetMWFOutputImage());
119 
120  if (resWeightsArg.getValue() != "")
121  anima::writeImage<VectorOutputImageType> (resWeightsArg.getValue(),mainFilter->GetWeightsImage());
122 
123  if (resMeanParamArg.getValue() != "")
124  anima::writeImage<VectorOutputImageType> (resMeanParamArg.getValue(),mainFilter->GetMeanParamImage());
125 
126  if (resM0Arg.getValue() != "")
127  anima::writeImage<OutputImageType> (resM0Arg.getValue(),mainFilter->GetM0OutputImage());
128 
129  if (resB1Arg.getValue() != "")
130  anima::writeImage<OutputImageType> (resB1Arg.getValue(),mainFilter->GetB1OutputImage());
131 
132  if (resSigmaSqArg.getValue() != "")
133  anima::writeImage<OutputImageType> (resSigmaSqArg.getValue(),mainFilter->GetSigmaSquareOutputImage());
134 
135  return EXIT_SUCCESS;
136 }
int main(int argc, char **argv)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)