ANIMA  4.0
animaNLMeansPatientToGroupComparison.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <tclap/CmdLine.h>
3 
6 #include <itkTimeProbe.h>
7 
8 //Update progression of the process
9 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
10 {
11  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
12  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
13 }
14 
15 int main(int argc, char **argv)
16 {
17  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
18 
19  TCLAP::ValueArg<std::string> refLTArg("i","input","Test Image",true,"","test image",cmd);
20  TCLAP::ValueArg<std::string> dataLTArg("I","database","Database Image List",true,"","database image list",cmd);
21 
22  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",true,"","computation mask",cmd);
23  TCLAP::ValueArg<std::string> resArg("o","outputpval","P-values output image",true,"","P-values output image",cmd);
24 
25  TCLAP::ValueArg<std::string> dbMeanDistAveArg("d","dbmeanave","DB average mean distance image",true,"","DB average mean distance image",cmd);
26  TCLAP::ValueArg<std::string> dbMeanDistStdArg("D","dbmeanstd","DB std mean distance image",true,"","DB std mean distance image",cmd);
27  TCLAP::ValueArg<std::string> dbCovDistAveArg("","dbcovave","DB average covariance distance image",true,"","DB average covariance distance image",cmd);
28  TCLAP::ValueArg<std::string> dbCovDistStdArg("","dbcovstd","DB std covariance distance image",true,"","DB std covariance distance image",cmd);
29 
30  TCLAP::ValueArg<std::string> resScoreArg("O","outputscore","Score output image",false,"","Score output image",cmd);
31  TCLAP::ValueArg<std::string> resNumPatchesArg("","outputnpatches","Number of patches output image",false,"","Number of patches output image",cmd);
32 
33  TCLAP::ValueArg<double> weightThrArg("w","weightthr","NL weight threshold: patches around have to be similar enough (default: 0.0)",false,0.0,"NL weight threshold",cmd);
34  TCLAP::ValueArg<double> meanThrArg("M","patchmeanthr","Tolerance for means test (test if meansTest > meanDatabase + M * stdDatabase, default: M=2.5)",false,2.5,"NL mean patch proportion",cmd);
35  TCLAP::ValueArg<double> varThrArg("c","patchcovthr","Tolerance for covariance test (test if covDist > meanDatabase + c * stdDatabase, default: c=2.5)",false,2.5,"NL covariance patch proportion",cmd);
36 
37  TCLAP::ValueArg<double> betaArg("b","beta","Beta parameter for local noise estimation (default: 1)",false,1,"Beta for local noise estimation",cmd);
38 
39  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
40 
41  TCLAP::ValueArg<unsigned int> patchHSArg("","patchhalfsize","Patch half size in each direction (default: 1)",false,1,"patch half size",cmd);
42  TCLAP::ValueArg<unsigned int> patchSSArg("","patchstepsize","Patch step size for searching (default: 1)",false,1,"patch search step size",cmd);
43  TCLAP::ValueArg<unsigned int> patchNeighArg("n","patchneighborhood","Patch half neighborhood size (default: 2)",false,2,"patch search neighborhood size",cmd);
44 
45  try
46  {
47  cmd.parse(argc,argv);
48  }
49  catch (TCLAP::ArgException& e)
50  {
51  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
52  return EXIT_FAILURE;
53  }
54 
55  typedef itk::VectorImage<double,3> LogTensorImageType;
56  typedef anima::NLMeansPatientToGroupComparisonImageFilter<double> NLComparisonImageFilterType;
57 
58  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
59  callback->SetCallback(eventCallback);
60 
61  NLComparisonImageFilterType::Pointer mainFilter = NLComparisonImageFilterType::New();
62  mainFilter->SetComputationMask(anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
63  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
64 
65  mainFilter->SetWeightThreshold(weightThrArg.getValue());
66  mainFilter->SetMeanThreshold(meanThrArg.getValue());
67  mainFilter->SetVarianceThreshold(varThrArg.getValue());
68 
69  mainFilter->SetPatchHalfSize(patchHSArg.getValue());
70  mainFilter->SetSearchStepSize(patchSSArg.getValue());
71  mainFilter->SetSearchNeighborhood(patchNeighArg.getValue());
72  mainFilter->SetBetaParameter(betaArg.getValue());
73 
74  mainFilter->SetInput(0,anima::readImage <LogTensorImageType> (refLTArg.getValue()));
75  mainFilter->AddObserver(itk::ProgressEvent(), callback);
76 
77  std::ifstream fileIn(dataLTArg.getValue());
78 
79  while (!fileIn.eof())
80  {
81  char tmpStr[2048];
82  fileIn.getline(tmpStr,2048);
83 
84  if (strcmp(tmpStr,"") == 0)
85  continue;
86 
87  std::cout << "Loading database image " << tmpStr << "..." << std::endl;
88  mainFilter->AddDatabaseInput(anima::readImage <LogTensorImageType> (tmpStr));
89  }
90  fileIn.close();
91 
92  mainFilter->SetDatabaseMeanDistanceAverage(anima::readImage < itk::Image <double, 3> > (dbMeanDistAveArg.getValue()));
93  mainFilter->SetDatabaseMeanDistanceStd(anima::readImage < itk::Image <double, 3> > (dbMeanDistStdArg.getValue()));
94 
95  mainFilter->SetDatabaseCovarianceDistanceAverage(anima::readImage < itk::Image <double, 3> > (dbCovDistAveArg.getValue()));
96  mainFilter->SetDatabaseCovarianceDistanceStd(anima::readImage < itk::Image <double, 3> > (dbCovDistStdArg.getValue()));
97 
98  try
99  {
100  mainFilter->Update();
101  }
102  catch (itk::ExceptionObject &e)
103  {
104  std::cerr << e << std::endl;
105  return EXIT_FAILURE;
106  }
107 
108  anima::writeImage < itk::Image <double, 3> > (resArg.getValue(),mainFilter->GetOutput(0));
109 
110  if (resScoreArg.getValue() != "")
111  anima::writeImage < itk::Image <double, 3> > (resScoreArg.getValue(),mainFilter->GetOutput(1));
112 
113  if (resNumPatchesArg.getValue() != "")
114  anima::writeImage < itk::Image <double, 3> > (resNumPatchesArg.getValue(),mainFilter->GetOutput(2));
115 
116  return EXIT_SUCCESS;
117 }
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
int main(int argc, char **argv)
void writeImage(std::string filename, OutputImageType *img)
itk::SmartPointer< ImageType > readImage(std::string filename)