ANIMA  4.0
animaDenseMCMSVFBMRegistration.cxx
Go to the documentation of this file.
2 #include <animaMCMFileReader.h>
4 
5 #include <tclap/CmdLine.h>
6 #include <itkTimeProbe.h>
7 #include <animaMCMConstants.h>
8 
9 int main(int ac, const char** av)
10 {
11  const unsigned int Dimension = 3;
13  typedef PyramidBMType::InputImageType InputImageType;
14  typedef InputImageType::InternalPixelType InputInternalPixelType;
15 
16  // Parsing arguments
17  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
18 
19  // Setting up parameters
20  TCLAP::ValueArg<std::string> fixedArg("r","refimage","Fixed image",true,"","fixed image",cmd);
21  TCLAP::ValueArg<std::string> movingArg("m","movingimage","Moving image",true,"","moving image",cmd);
22  TCLAP::ValueArg<std::string> outArg("o","outputimage","Output (registered) image",true,"","output image",cmd);
23  TCLAP::ValueArg<std::string> outputTransformArg("O","outtransform","Output transformation",false,"","output transform",cmd);
24  TCLAP::SwitchArg ppdImageArg("P","ppd", "Re-orientation strategy set to preservation of principal direction (default: finite strain)", cmd, false);
25 
26  TCLAP::ValueArg<unsigned int> blockSizeArg("","bs","Block size (default: 5)",false,5,"block size",cmd);
27  TCLAP::ValueArg<unsigned int> blockSpacingArg("","sp","Block spacing (default: 2)",false,2,"block spacing",cmd);
28  TCLAP::ValueArg<double> stdevThresholdArg("s","stdev","Threshold block standard deviation (default: 0.1)",false,0.1,"block minimal standard deviation",cmd);
29  TCLAP::ValueArg<double> percentageKeptArg("k","per-kept","Percentage of blocks with the highest variance kept (default: 0.8)",false,0.8,"percentage of blocks kept",cmd);
30 
31  TCLAP::ValueArg<unsigned int> blockTransfoArg("t","in-transform","Transformation computed between blocks (0: translation, 1: rigid, 2: affine, default: 0)",false,0,"transformation between blocks",cmd);
32  TCLAP::ValueArg<unsigned int> blockMetricArg("","metric","Similarity metric between blocks (0: basic mean squares, 1: one to on basic mean squares, 2: MCM mean squares, 3: MT pairing correlation, 4: MCM correlation, default: 1)",false,1,"similarity metric",cmd);
33  TCLAP::ValueArg<unsigned int> blockOrientationArg("","bor","Re-orientation strategy when matching blocks (0: none, 1: finite strain, 2: PPD, default: 2)",false,2,"block re-orientation",cmd);
34 
35  TCLAP::ValueArg<double> smallDeltaArg("", "small-delta", "Diffusion small delta (in seconds)", false, anima::DiffusionSmallDelta, "small delta", cmd);
36  TCLAP::ValueArg<double> bigDeltaArg("", "big-delta", "Diffusion big delta (in seconds)", false, anima::DiffusionBigDelta, "big delta", cmd);
37  TCLAP::ValueArg<std::string> bvalArg("b","bvals","B-values",false,"","b-values",cmd);
38  TCLAP::ValueArg<std::string> bvecArg("v","bvec","Gradient direction",false,"","gradient directions",cmd);
39 
40  TCLAP::ValueArg<unsigned int> optimizerArg("","opt","Optimizer for optimal block search (0: Exhaustive, 1: Bobyqa, default: 1)",false,1,"optimizer",cmd);
41  TCLAP::ValueArg<unsigned int> maxIterationsArg("","mi","Maximum block match iterations (default: 10)",false,10,"maximum iterations",cmd);
42  TCLAP::ValueArg<double> minErrorArg("","me","Minimal distance between consecutive estimated transforms (default: 0.01)",false,0.01,"minimal distance between transforms",cmd);
43 
44  TCLAP::ValueArg<unsigned int> optimizerMaxIterationsArg("","oi","Maximum iterations for local optimizer (default: 100)",false,100,"maximum local optimizer iterations",cmd);
45 
46  TCLAP::ValueArg<double> searchRadiusArg("","sr","Search radius in pixels (exhaustive search window, rho start for bobyqa, default: 2)",false,2,"optimizer search radius",cmd);
47  TCLAP::ValueArg<double> searchAngleRadiusArg("","sar","Search angle radius in degrees (rho start for bobyqa, default: 5)",false,5,"optimizer search angle radius",cmd);
48  TCLAP::ValueArg<double> searchScaleRadiusArg("","scr","Search scale radius (rho start for bobyqa, default: 0.1)",false,0.1,"optimizer search scale radius",cmd);
49  TCLAP::ValueArg<double> finalRadiusArg("","fr","Final radius (rho end for bobyqa, default: 0.001)",false,0.001,"optimizer final radius",cmd);
50  TCLAP::ValueArg<double> searchStepArg("","st","Search step for exhaustive search (default: 1)",false,1,"exhaustive optimizer search step",cmd);
51 
52  TCLAP::ValueArg<double> translateUpperBoundArg("","tub","Upper bound on translation for bobyqa (in voxels, default: 10)",false,10,"Bobyqa translate upper bound",cmd);
53  TCLAP::ValueArg<double> angleUpperBoundArg("","aub","Upper bound on angles for bobyqa (in degrees, default: 180)",false,180,"Bobyqa angle upper bound",cmd);
54  TCLAP::ValueArg<double> scaleUpperBoundArg("","scu","Upper bound on scale for bobyqa (default: 3)",false,3,"Bobyqa scale upper bound",cmd);
55 
56  TCLAP::ValueArg<unsigned int> symmetryArg("","sym-reg","Registration symmetry type (0: asymmetric, 1: symmetric, 2: kissing, default: 0)",false,0,"symmetry type",cmd);
57  TCLAP::ValueArg<unsigned int> agregatorArg("a","agregator","Transformation agregator type (0: Baloo, 1: M-smoother, default: 0)",false,0,"agregator type",cmd);
58  TCLAP::ValueArg<double> extrapolationSigmaArg("","fs","Sigma for extrapolation of local pairings (default: 3)",false,3,"extrapolation sigma",cmd);
59  TCLAP::ValueArg<double> elasticSigmaArg("","es","Sigma for elastic regularization (default: 3)",false,3,"elastic regularization sigma",cmd);
60  TCLAP::ValueArg<double> outlierSigmaArg("","os","Sigma for outlier rejection among local pairings (default: 3)",false,3,"outlier rejection sigma",cmd);
61  TCLAP::ValueArg<double> mEstimateConvergenceThresholdArg("","met","Threshold to consider m-estimator converged (default: 0.01)",false,0.01,"m-estimation convergence threshold",cmd);
62  TCLAP::ValueArg<double> neighborhoodApproximationArg("","na","Half size of the neighborhood approximation (multiplied by extrapolation sigma, default: 2.5)",false,2.5,"half size of neighborhood approximation",cmd);
63  TCLAP::ValueArg<unsigned int> bchOrderArg("B","bch-order","BCH composition order (default: 1)",false,1,"BCH order",cmd);
64  TCLAP::ValueArg<unsigned int> expOrderArg("e","exp-order","Order of field exponentiation approximation (in between 0 and 1, default: 0)",false,0,"exponentiation order",cmd);
65 
66  TCLAP::ValueArg<unsigned int> numPyramidLevelsArg("p","pyr","Number of pyramid levels (default: 3)",false,3,"number of pyramid levels",cmd);
67  TCLAP::ValueArg<unsigned int> lastPyramidLevelArg("l","last-level","Index of the last pyramid level explored (default: 0)",false,0,"last pyramid level",cmd);
68  TCLAP::ValueArg<unsigned int> numThreadsArg("T","threads","Number of execution threads (default: 0 = all cores)",false,0,"number of threads",cmd);
69 
70  try
71  {
72  cmd.parse(ac,av);
73  }
74  catch (TCLAP::ArgException& e)
75  {
76  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
77  return EXIT_FAILURE;
78  }
79 
80  PyramidBMType::Pointer matcher = PyramidBMType::New();
81 
83  refReader.SetFileName(fixedArg.getValue());
84  refReader.Update();
85 
86  matcher->SetReferenceImage(refReader.GetModelVectorImage());
87 
89  floReader.SetFileName(movingArg.getValue());
90  floReader.Update();
91 
92  matcher->SetFloatingImage(floReader.GetModelVectorImage());
93 
94  if ((bvalArg.getValue() != "")&&(bvecArg.getValue() != ""))
95  {
96  typedef anima::GradientFileReader <vnl_vector_fixed <double,3>, double> GradientReaderType;
97  GradientReaderType gradientReader;
98  gradientReader.SetGradientFileName(bvecArg.getValue());
99  gradientReader.SetBValueBaseString(bvalArg.getValue());
100  gradientReader.SetGradientIndependentNormalization(true);
101  gradientReader.SetSmallDelta(smallDeltaArg.getValue());
102  gradientReader.SetBigDelta(bigDeltaArg.getValue());
103 
104  gradientReader.Update();
105 
106  matcher->SetSmallDelta(smallDeltaArg.getValue());
107  matcher->SetBigDelta(bigDeltaArg.getValue());
108  matcher->SetGradientStrengths(gradientReader.GetGradientStrengths());
109  matcher->SetGradientDirections(gradientReader.GetGradients());
110  }
111 
112  // Setting matcher arguments
113  matcher->SetBlockSize( blockSizeArg.getValue() );
114  matcher->SetBlockSpacing( blockSpacingArg.getValue() );
115  matcher->SetStDevThreshold( stdevThresholdArg.getValue() );
116  matcher->SetTransform( (Transform) blockTransfoArg.getValue() );
117  matcher->SetMetric( (Metric) blockMetricArg.getValue() );
118  matcher->SetMetricOrientation( (MetricOrientationType) blockOrientationArg.getValue() );
119  matcher->SetFiniteStrainImageReorientation(!ppdImageArg.isSet());
120  matcher->SetOptimizer( (Optimizer) optimizerArg.getValue() );
121  matcher->SetMaximumIterations( maxIterationsArg.getValue() );
122  matcher->SetMinimalTransformError( minErrorArg.getValue() );
123  matcher->SetFinalRadius(finalRadiusArg.getValue());
124  matcher->SetOptimizerMaximumIterations( optimizerMaxIterationsArg.getValue() );
125  matcher->SetSearchRadius( searchRadiusArg.getValue() );
126  matcher->SetSearchAngleRadius( searchAngleRadiusArg.getValue() );
127  matcher->SetSearchScaleRadius( searchScaleRadiusArg.getValue() );
128  matcher->SetStepSize( searchStepArg.getValue() );
129  matcher->SetTranslateUpperBound( translateUpperBoundArg.getValue() );
130  matcher->SetAngleUpperBound( angleUpperBoundArg.getValue() );
131  matcher->SetScaleUpperBound( scaleUpperBoundArg.getValue() );
132  matcher->SetSymmetryType( (SymmetryType) symmetryArg.getValue() );
133  matcher->SetAgregator( (Agregator) agregatorArg.getValue() );
134  matcher->SetExtrapolationSigma(extrapolationSigmaArg.getValue());
135  matcher->SetElasticSigma(elasticSigmaArg.getValue());
136  matcher->SetOutlierSigma(outlierSigmaArg.getValue());
137  matcher->SetMEstimateConvergenceThreshold(mEstimateConvergenceThresholdArg.getValue());
138  matcher->SetNeighborhoodApproximation(neighborhoodApproximationArg.getValue());
139  matcher->SetBCHCompositionOrder(bchOrderArg.getValue());
140  matcher->SetExponentiationOrder(expOrderArg.getValue());
141  matcher->SetNumberOfPyramidLevels( numPyramidLevelsArg.getValue() );
142  matcher->SetLastPyramidLevel( lastPyramidLevelArg.getValue() );
143 
144  if (numThreadsArg.getValue() != 0)
145  matcher->SetNumberOfWorkUnits( numThreadsArg.getValue() );
146 
147  matcher->SetPercentageKept( percentageKeptArg.getValue() );
148 
149  matcher->SetResultFile( outArg.getValue() );
150  matcher->SetOutputTransformFile( outputTransformArg.getValue() );
151 
152  itk::TimeProbe timer;
153 
154  timer.Start();
155 
156  try
157  {
158  matcher->Update();
159  matcher->WriteOutputs();
160  }
161  catch (itk::ExceptionObject &e)
162  {
163  std::cerr << e << std::endl;
164  return EXIT_FAILURE;
165  }
166 
167  timer.Stop();
168 
169  std::cout << "Elapsed Time: " << timer.GetTotal() << timer.GetUnit() << std::endl;
170 
171  return EXIT_SUCCESS;
172 }
int main(int ac, const char **av)
const double DiffusionBigDelta
Default big delta value (classical values)
const double DiffusionSmallDelta
Default small delta value (classical values)
OutputImagePointer & GetModelVectorImage()
void SetGradientFileName(std::string fName)
void SetFileName(std::string fileName)