2 #include <tclap/CmdLine.h> 4 #include <itkImageFileReader.h> 5 #include <itkImageFileWriter.h> 8 #include <itkTimeProbe.h> 10 #include <boost/lexical_cast.hpp> 11 #include <boost/algorithm/string.hpp> 13 #include <itkCommand.h> 16 void eventCallback (itk::Object* caller,
const itk::EventObject& event,
void* clientData)
18 itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
19 std::cout<<
"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<
"%"<<std::flush;
22 int main(
int argc,
char **argv)
24 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
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);
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);
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);
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);
44 TCLAP::ValueArg<double> gammaToleranceApproxArg(
"",
"g-tol",
"Gamma approximation tolerance (default: 1.0e-8)",
false,1.0e-8,
"Gamma approximation tolerance",cmd);
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);
52 catch (TCLAP::ArgException& e)
54 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
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;
65 FilterType::Pointer mainFilter = FilterType::New();
67 unsigned int numInputs = anima::setMultipleImageFilterInputsFromFileName<InputImageType,FilterType>(t2Arg.getValue(),mainFilter);
69 mainFilter->SetEchoSpacing(echoSpacingArg.getValue());
70 mainFilter->SetT2FlipAngles(t2FlipAngleArg.getValue() * M_PI / 180.0,numInputs);
71 mainFilter->SetT2ExcitationFlipAngle(excitationT2FlipAngleArg.getValue() * M_PI / 180.0);
73 mainFilter->SetGammaIntegralTolerance(gammaToleranceApproxArg.getValue());
74 mainFilter->SetConstrainedParameters(constrainArg.isSet());
76 if (t1MapArg.getValue() !=
"")
78 InputImageReaderType::Pointer t1MapRead = InputImageReaderType::New();
79 t1MapRead->SetFileName(t1MapArg.getValue().c_str());
82 mainFilter->SetT1Map(t1MapRead->GetOutput());
85 if (maskArg.getValue() !=
"")
87 typedef itk::ImageFileReader < itk::Image <unsigned char, 3> > itkMaskReader;
88 itkMaskReader::Pointer maskRead = itkMaskReader::New();
89 maskRead->SetFileName(maskArg.getValue().c_str());
92 mainFilter->SetComputationMask(maskRead->GetOutput());
95 mainFilter->SetAverageSignalThreshold(backgroundSignalThresholdArg.getValue());
96 mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
98 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
100 mainFilter->AddObserver(itk::ProgressEvent(), callback );
102 itk::TimeProbe tmpTime;
107 mainFilter->Update();
109 catch (itk::ExceptionObject &e)
111 std::cerr << e << std::endl;
116 std::cout <<
"Estimation computation time: " << tmpTime.GetTotal() << std::endl;
118 anima::writeImage<OutputImageType> (resMWFArg.getValue(),mainFilter->GetMWFOutputImage());
120 if (resWeightsArg.getValue() !=
"")
121 anima::writeImage<VectorOutputImageType> (resWeightsArg.getValue(),mainFilter->GetWeightsImage());
123 if (resMeanParamArg.getValue() !=
"")
124 anima::writeImage<VectorOutputImageType> (resMeanParamArg.getValue(),mainFilter->GetMeanParamImage());
126 if (resM0Arg.getValue() !=
"")
127 anima::writeImage<OutputImageType> (resM0Arg.getValue(),mainFilter->GetM0OutputImage());
129 if (resB1Arg.getValue() !=
"")
130 anima::writeImage<OutputImageType> (resB1Arg.getValue(),mainFilter->GetB1OutputImage());
132 if (resSigmaSqArg.getValue() !=
"")
133 anima::writeImage<OutputImageType> (resSigmaSqArg.getValue(),mainFilter->GetSigmaSquareOutputImage());
int main(int argc, char **argv)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)