ANIMA  4.0
animaSymmetryConstrainedRegistration.cxx
Go to the documentation of this file.
2 
3 #include <itkTimeProbe.h>
5 #include <itkTransformFileReader.h>
6 
7 #include <tclap/CmdLine.h>
8 
9 int main(int ac, const char** av)
10 {
11  // Parsing arguments
12  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
13 
14  // Setting up parameters
15  TCLAP::ValueArg<std::string> fixedArg("r","refimage","Fixed image",true,"","fixed image",cmd);
16  TCLAP::ValueArg<std::string> movingArg("m","movingimage","Moving image",true,"","moving image",cmd);
17 
18  TCLAP::ValueArg<std::string> fixedSymmetryArg("","ref-sym","Fixed symmetry",true,"","fixed symmetry",cmd);
19  TCLAP::ValueArg<std::string> movingSymmetryArg("","moving-sym","Moving symmetry",true,"","moving symmetry",cmd);
20 
21  TCLAP::ValueArg<std::string> outArg("o","outputimage","Output (registered) image",true,"","output image",cmd);
22  TCLAP::ValueArg<std::string> outputTransformArg("O","outtransform","Output transformation",false,"","output transform",cmd);
23 
24  TCLAP::ValueArg<unsigned int> metricArg("","metric","Similarity metric (0: mutual information, 1: normalized mutual information, 2: mean squares, default: 2)",false,2,"similarity metric",cmd);
25  TCLAP::SwitchArg fastRegArg("F","fast-reg","registration on the central 2D slice only",cmd,false);
26 
27  TCLAP::ValueArg<unsigned int> optimizerMaxIterationsArg("","oi","Maximum iterations for local optimizer (default: 100)",false,100,"maximum local optimizer iterations",cmd);
28  TCLAP::ValueArg<unsigned int> histoSizeArg("","hs","Histogram size for mutual information (default: 128)",false,128,"histogram size",cmd);
29 
30  TCLAP::ValueArg<double> translateUpperBoundArg("","tub","Upper bound on translation for bobyqa (in voxels, default: 10)",false,10,"Bobyqa translate upper bound",cmd);
31  TCLAP::ValueArg<double> angleUpperBoundArg("","aub","Upper bound on angles for bobyqa (in degrees, default: 180)",false,180,"Bobyqa angle upper bound",cmd);
32 
33  TCLAP::ValueArg<unsigned int> numPyramidLevelsArg("p","pyr","Number of pyramid levels (default: 3)",false,3,"number of pyramid levels",cmd);
34  TCLAP::ValueArg<unsigned int> numThreadsArg("T","threads","Number of execution threads (default: 0 = all cores)",false,0,"number of threads",cmd);
35 
36  try
37  {
38  cmd.parse(ac,av);
39  }
40  catch (TCLAP::ArgException& e)
41  {
42  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
43  return EXIT_FAILURE;
44  }
45 
47  typedef itk::Image <double, 3> InputImageType;
48 
49  BridgeType::Pointer matcher = BridgeType::New();
50 
51  matcher->SetReferenceImage(anima::readImage <InputImageType> (fixedArg.getValue()));
52  matcher->SetFloatingImage(anima::readImage <InputImageType> (movingArg.getValue()));
53 
54  matcher->SetResultFile( outArg.getValue() );
55  matcher->SetOutputTransformFile( outputTransformArg.getValue() );
56 
57  matcher->SetMetric( (Metric) metricArg.getValue() );
58  matcher->SetOptimizerMaximumIterations( optimizerMaxIterationsArg.getValue() );
59  matcher->SetUpperBoundAngle(angleUpperBoundArg.getValue() * M_PI / 180.0);
60  matcher->SetTranslateUpperBound(translateUpperBoundArg.getValue());
61  matcher->SetHistogramSize(histoSizeArg.getValue());
62  matcher->SetNumberOfPyramidLevels( numPyramidLevelsArg.getValue() );
63  matcher->SetFastRegistration(fastRegArg.isSet());
64 
65  if (numThreadsArg.getValue() != 0)
66  matcher->SetNumberOfWorkUnits( numThreadsArg.getValue() );
67 
68  typedef BridgeType::BaseTransformType BaseTransformType;
69  itk::TransformFileReader::Pointer tmpTrRead = itk::TransformFileReader::New();
70  tmpTrRead->SetFileName(fixedSymmetryArg.getValue());
71 
72  try
73  {
74  tmpTrRead->Update();
75 
76  itk::TransformFileReader::TransformListType trsfList = *(tmpTrRead->GetTransformList());
77  itk::TransformFileReader::TransformListType::iterator tr_it = trsfList.begin();
78 
79  matcher->SetRefSymmetryTransform (dynamic_cast< BaseTransformType *> ((*tr_it).GetPointer()));
80  }
81  catch (itk::ExceptionObject &e)
82  {
83  std::cerr << "Unable to read reference symmetry transform... " << e << std::endl;
84  return EXIT_FAILURE;
85  }
86 
87  tmpTrRead = itk::TransformFileReader::New();
88  tmpTrRead->SetFileName(movingSymmetryArg.getValue());
89 
90  try
91  {
92  tmpTrRead->Update();
93 
94  itk::TransformFileReader::TransformListType trsfList = *(tmpTrRead->GetTransformList());
95  itk::TransformFileReader::TransformListType::iterator tr_it = trsfList.begin();
96 
97  matcher->SetFloSymmetryTransform (dynamic_cast< BaseTransformType *> ((*tr_it).GetPointer()));
98  }
99  catch (itk::ExceptionObject &e)
100  {
101  std::cerr << "Unable to read Floating symmetry transform... " << e << std::endl;
102  return EXIT_FAILURE;
103  }
104 
105  itk::TimeProbe timer;
106 
107  timer.Start();
108 
109  try
110  {
111  matcher->Update();
112  }
113  catch (itk::ExceptionObject &err)
114  {
115  std::cerr << err << std::endl;
116  return EXIT_FAILURE;
117  }
118 
119  matcher->WriteOutputs();
120 
121  timer.Stop();
122 
123  std::cout << "Elapsed Time: " << timer.GetTotal() << timer.GetUnit() << std::endl;
124 
125  return EXIT_SUCCESS;
126 }
int main(int ac, const char **av)