2 #include <tclap/CmdLine.h> 4 #include <itkImageFileReader.h> 5 #include <itkImageFileWriter.h> 8 #include <itkTimeProbe.h> 11 void eventCallback (itk::Object* caller,
const itk::EventObject& event,
void* clientData)
13 itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
14 std::cout<<
"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<
"%"<<std::flush;
17 int main(
int argc,
char **argv)
19 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
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);
24 TCLAP::ValueArg<std::string> t1MapArg(
"",
"t1",
"T1 map",
false,
"",
"T1 map",cmd);
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);
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);
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);
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);
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);
47 catch (TCLAP::ArgException& e)
49 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
53 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
56 typedef itk::Image <double,3> InputImageType;
57 typedef InputImageType OutputImageType;
60 FilterType::Pointer mainFilter = FilterType::New();
63 unsigned int numInputs = anima::setMultipleImageFilterInputsFromFileName<InputImageType,FilterType>(t2Arg.getValue(),mainFilter);
65 mainFilter->SetEchoSpacing(echoSpacingArg.getValue());
66 mainFilter->SetT2FlipAngles(t2FlipAngleArg.getValue() * M_PI / 180.0,numInputs);
67 mainFilter->SetT2ExcitationFlipAngle(excitationT2FlipAngleArg.getValue() * M_PI / 180.0);
69 mainFilter->SetT2UpperBound(upperBoundT2Arg.getValue());
70 mainFilter->SetTRValue(trArg.getValue());
72 mainFilter->SetMaximumOptimizerIterations(numOptimizerIterArg.getValue());
73 mainFilter->SetOptimizerStopCondition(optimizerStopConditionArg.getValue());
75 if (t1MapArg.getValue() !=
"")
76 mainFilter->SetT1Map(anima::readImage <InputImageType> (t1MapArg.getValue()));
78 if (maskArg.getValue() !=
"")
79 mainFilter->SetComputationMask(
anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
81 mainFilter->SetAverageSignalThreshold(backgroundSignalThresholdArg.getValue());
82 mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
84 itk::TimeProbe tmpTime;
87 mainFilter->AddObserver(itk::ProgressEvent(), callback);
92 std::cout <<
"\nTotal computation time: " << tmpTime.GetTotal() << std::endl;
94 anima::writeImage <OutputImageType> (resT2Arg.getValue(),mainFilter->GetOutput(0));
96 if (resM0Arg.getValue() !=
"")
97 anima::writeImage <OutputImageType> (resM0Arg.getValue(),mainFilter->GetOutput(1));
99 if (resB1Arg.getValue() !=
"")
100 anima::writeImage <OutputImageType> (resB1Arg.getValue(),mainFilter->GetOutput(2));
int main(int argc, char **argv)
itk::SmartPointer< ImageType > readImage(std::string filename)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)