ANIMA  4.0
animaLocalPatchCovarianceDistance.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> dataLTArg("i","database","Database Image List",true,"","database image list",cmd);
19 
20  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",true,"","computation mask",cmd);
21  TCLAP::ValueArg<std::string> resArg("o","outputmean","Average distance output image",true,"","Average distance output image",cmd);
22 
23  TCLAP::ValueArg<std::string> resStdArg("O","outputstd","Standard deviation output image",false,"","Standard deviation output image",cmd);
24 
25  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
26 
27  TCLAP::ValueArg<unsigned int> patchHSArg("","patchhalfsize","Patch half size in each direction (default: 1)",false,1,"patch half size",cmd);
28 
29  try
30  {
31  cmd.parse(argc,argv);
32  }
33  catch (TCLAP::ArgException& e)
34  {
35  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
36  return EXIT_FAILURE;
37  }
38 
39  typedef itk::VectorImage<double,3> LogTensorImageType;
41 
42  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
43  callback->SetCallback(eventCallback);
44 
45  MainFilterType::Pointer mainFilter = MainFilterType::New();
46  mainFilter->SetComputationMask(anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
47  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
48 
49  mainFilter->SetPatchHalfSize(patchHSArg.getValue());
50  mainFilter->AddObserver(itk::ProgressEvent(), callback);
51 
52  std::ifstream fileIn(dataLTArg.getValue());
53 
54  unsigned int count = 0;
55  while (!fileIn.eof())
56  {
57  char tmpStr[2048];
58  fileIn.getline(tmpStr,2048);
59 
60  if (strcmp(tmpStr,"") == 0)
61  continue;
62 
63  std::cout << "Loading database image " << tmpStr << "..." << std::endl;
64  mainFilter->SetInput(count,anima::readImage <LogTensorImageType> (tmpStr));
65  ++count;
66  }
67  fileIn.close();
68 
69  try
70  {
71  mainFilter->Update();
72  }
73  catch(itk::ExceptionObject &e)
74  {
75  std::cerr << e << std::endl;
76  return EXIT_FAILURE;
77  }
78 
79  anima::writeImage < itk::Image <double, 3> > (resArg.getValue(),mainFilter->GetOutput(0));
80 
81  if (resStdArg.getValue() != "")
82  anima::writeImage < itk::Image <double, 3> > (resStdArg.getValue(),mainFilter->GetOutput(1));
83 
84  return EXIT_SUCCESS;
85 }
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)