ANIMA  4.0
animaPatientToGroupComparison.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <tclap/CmdLine.h>
3 
6 
7 //Update progression of the process
8 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
9 {
10  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
11  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
12 }
13 
14 int main(int argc, char **argv)
15 {
16  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
17 
18  TCLAP::ValueArg<std::string> refLTArg("i","input","Test Image",true,"","test image",cmd);
19  TCLAP::ValueArg<std::string> dataLTArg("I","database","Database Image List",true,"","database image list",cmd);
20 
21  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",true,"","computation mask",cmd);
22  TCLAP::ValueArg<std::string> resArg("o","outputname","Z-Score output image",true,"","Z-Score output image",cmd);
23  TCLAP::ValueArg<std::string> resPValArg("O","outpvalname","P-value output image",true,"","P-Value output image",cmd);
24 
25  TCLAP::ValueArg<std::string> statTestArg("t","stat-test","Statistical test to use ([fisher],chi)",false,"fisher","statistical test",cmd);
26  TCLAP::ValueArg<double> expVarArg("e","expvar","PCA threshold: threshold on eigenvalues to compute the new basis (default: 0.5)",false,0.5,"PCA threshold",cmd);
27  TCLAP::ValueArg<unsigned int> numEigenArg("E","numeigenpca","Number of eigenvalues to keep (default: 6)",false,6,"Number of PCA eigen values",cmd);
28 
29  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
30 
31  try
32  {
33  cmd.parse(argc,argv);
34  }
35  catch (TCLAP::ArgException& e)
36  {
37  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
38  return EXIT_FAILURE;
39  }
40 
41  typedef itk::VectorImage<double,3> LogTensorImageType;
42  typedef anima::PatientToGroupComparisonImageFilter<double> MAZScoreImageFilterType;
43 
44  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
45  callback->SetCallback(eventCallback);
46 
47  MAZScoreImageFilterType::Pointer mainFilter = MAZScoreImageFilterType::New();
48  mainFilter->SetComputationMask(anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
49  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
50 
51  mainFilter->SetInput(anima::readImage <LogTensorImageType> (refLTArg.getValue()));
52  mainFilter->SetExplainedRatio(expVarArg.getValue());
53  mainFilter->SetNumEigenValuesPCA(numEigenArg.getValue());
54 
55  if (statTestArg.getValue() == "chi")
56  mainFilter->SetStatisticalTestType(MAZScoreImageFilterType::CHI_SQUARE);
57  else
58  mainFilter->SetStatisticalTestType(MAZScoreImageFilterType::FISHER);
59 
60  std::ifstream fileIn(dataLTArg.getValue());
61  if (!fileIn.is_open())
62  {
63  std::cerr << "Could not open data file (" << dataLTArg.getValue() << ")" << std::endl;
64  return EXIT_FAILURE;
65  }
66 
67  while (!fileIn.eof())
68  {
69  char tmpStr[2048];
70  fileIn.getline(tmpStr,2048);
71 
72  if (strcmp(tmpStr,"") == 0)
73  continue;
74 
75  std::cout << "Loading tensor image " << tmpStr << "..." << std::endl;
76  mainFilter->AddDatabaseInput(anima::readImage <LogTensorImageType> (tmpStr));
77  }
78  fileIn.close();
79 
80  mainFilter->AddObserver(itk::ProgressEvent(), callback);
81 
82  try
83  {
84  mainFilter->Update();
85  }
86  catch (itk::ExceptionObject &e)
87  {
88  std::cerr << e << std::endl;
89  return EXIT_FAILURE;
90  }
91 
92  anima::writeImage < itk::Image <double, 3> > (resArg.getValue(),mainFilter->GetOutput(0));
93  anima::writeImage < itk::Image <double, 3> > (resPValArg.getValue(),mainFilter->GetOutput(1));
94 
95  return EXIT_SUCCESS;
96 }
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
itk::SmartPointer< ImageType > readImage(std::string filename)
int main(int argc, char **argv)
Implements patient to group comparison as in http://dx.doi.org/10.1007/978-3-540-85988-8_116.