18 #ifndef sitkImageRegistrationMethod_h
19 #define sitkImageRegistrationMethod_h
38 template<
typename TInternalComputationValueType>
class ObjectToObjectOptimizerBaseTemplate;
39 template<
typename TFixedImage,
40 typename TMovingImage,
41 typename TVirtualImage,
42 typename TInternalComputationValueType,
43 typename TMetricTraits >
44 class ImageToImageMetricv4;
46 template<
typename TFixedImageType,
47 typename TMovingImageType,
48 typename TVirtualImageType,
50 class DefaultImageToImageMetricTraitsv4;
52 template<
typename TMetric>
class RegistrationParameterScalesEstimator;
54 template<
unsigned int VDimension>
class SpatialObject;
64 class BSplineTransform;
101 std::string
GetName()
const override {
return std::string(
"ImageRegistrationMethod"); }
109 std::string ToString()
const override;
116 {
return this->m_Interpolator; }
118 { this->m_Interpolator = Interpolator;
return *
this; }
137 #if !defined(SWIG) || defined(JAVASWIG) || defined(CSHARPSWIG)
139 SITK_RETURN_SELF_TYPE_HEADER SetInitialTransform (
const Transform &transform );
141 SITK_RETURN_SELF_TYPE_HEADER SetInitialTransform (
Transform &transform,
bool inPlace=
true );
143 {
return this->m_InitialTransform; }
145 {
return this->m_InitialTransformInPlace;}
165 const std::vector<unsigned int> &scaleFactors=std::vector<unsigned int>() );
181 { this->m_MovingInitialTransform = transform;
return *
this; }
183 {
return this->m_MovingInitialTransform; }
197 { this->m_FixedInitialTransform = transform;
return *
this; }
199 {
return this->m_FixedInitialTransform; }
207 SITK_RETURN_SELF_TYPE_HEADER SetVirtualDomain(
const std::vector<uint32_t> &virtualSize,
208 const std::vector<double> &virtualOrigin,
209 const std::vector<double> &virtualSpacing,
210 const std::vector<double> &virtualDirection );
211 SITK_RETURN_SELF_TYPE_HEADER SetVirtualDomainFromImage(
const Image &virtualImage );
220 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsANTSNeighborhoodCorrelation(
unsigned int radius );
226 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsCorrelation( );
232 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsDemons(
double intensityDifferenceThreshold = 0.001 );
238 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsJointHistogramMutualInformation(
unsigned int numberOfHistogramBins = 20,
239 double varianceForJointPDFSmoothing = 1.5);
245 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsMeanSquares( );
252 SITK_RETURN_SELF_TYPE_HEADER SetMetricAsMattesMutualInformation(
unsigned int numberOfHistogramBins = 50 );
264 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsConjugateGradientLineSearch(
double learningRate,
265 unsigned int numberOfIterations,
266 double convergenceMinimumValue = 1e-6,
267 unsigned int convergenceWindowSize = 10,
268 double lineSearchLowerLimit = 0,
269 double lineSearchUpperLimit = 5.0,
270 double lineSearchEpsilon = 0.01,
271 unsigned int lineSearchMaximumIterations = 20,
272 EstimateLearningRateType estimateLearningRate = Once,
273 double maximumStepSizeInPhysicalUnits = 0.0 );
279 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsRegularStepGradientDescent(
double learningRate,
281 unsigned int numberOfIterations,
282 double relaxationFactor=0.5,
283 double gradientMagnitudeTolerance = 1e-4,
284 EstimateLearningRateType estimateLearningRate = Never,
285 double maximumStepSizeInPhysicalUnits = 0.0);
291 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsGradientDescent(
double learningRate,
292 unsigned int numberOfIterations,
293 double convergenceMinimumValue = 1e-6,
294 unsigned int convergenceWindowSize = 10,
295 EstimateLearningRateType estimateLearningRate = Once,
296 double maximumStepSizeInPhysicalUnits = 0.0);
302 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsGradientDescentLineSearch(
double learningRate,
303 unsigned int numberOfIterations,
304 double convergenceMinimumValue = 1e-6,
305 unsigned int convergenceWindowSize = 10,
306 double lineSearchLowerLimit = 0,
307 double lineSearchUpperLimit = 5.0,
308 double lineSearchEpsilon = 0.01,
309 unsigned int lineSearchMaximumIterations = 20,
310 EstimateLearningRateType estimateLearningRate = Once,
311 double maximumStepSizeInPhysicalUnits = 0.0 );
319 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsLBFGSB(
double gradientConvergenceTolerance = 1e-5,
320 unsigned int numberOfIterations = 500,
321 unsigned int maximumNumberOfCorrections = 5,
322 unsigned int maximumNumberOfFunctionEvaluations = 2000,
323 double costFunctionConvergenceFactor = 1e+7,
324 double lowerBound = std::numeric_limits<double>::min(),
325 double upperBound = std::numeric_limits<double>::max(),
326 bool trace =
false );
340 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsLBFGS2(
double solutionAccuracy = 1e-5,
341 unsigned int numberOfIterations = 0,
342 unsigned int hessianApproximateAccuracy = 6,
343 unsigned int deltaConvergenceDistance = 0,
344 double deltaConvergenceTolerance = 1e-5,
345 unsigned int lineSearchMaximumEvaluations = 40,
346 double lineSearchMinimumStep = 1e-20,
347 double lineSearchMaximumStep = 1e20,
348 double lineSearchAccuracy = 1e-4);
367 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsExhaustive(
const std::vector<unsigned int> &numberOfSteps,
368 double stepLength = 1.0 );
374 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsAmoeba(
double simplexDelta,
375 unsigned int numberOfIterations,
376 double parametersConvergenceTolerance=1e-8,
377 double functionConvergenceTolerance=1e-4,
378 bool withRestarts =
false );
391 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerWeights(
const std::vector<double> &weights);
392 std::vector<double> GetOptimizerWeights( )
const;
399 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsPowell(
unsigned int numberOfIterations = 100,
400 unsigned int maximumLineIterations = 100,
401 double stepLength = 1,
402 double stepTolerance = 1e-6,
403 double valueTolerance = 1e-6 );
413 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerAsOnePlusOneEvolutionary(
unsigned int numberOfIterations = 100,
414 double epsilon = 1.5e-4,
415 double initialRadius = 1.01,
416 double growthFactor = -1.0,
417 double shrinkFactor = -1.0,
423 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerScales(
const std::vector<double> &scales );
431 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerScalesFromJacobian(
unsigned int centralRegionRadius = 5 );
438 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerScalesFromIndexShift(
unsigned int centralRegionRadius = 5,
439 double smallParameterVariation = 0.01 );
447 SITK_RETURN_SELF_TYPE_HEADER SetOptimizerScalesFromPhysicalShift(
unsigned int centralRegionRadius = 5,
448 double smallParameterVariation = 0.01 );
460 SITK_RETURN_SELF_TYPE_HEADER SetMetricFixedMask(
const Image &binaryMask );
471 SITK_RETURN_SELF_TYPE_HEADER SetMetricMovingMask(
const Image &binaryMask );
491 SITK_RETURN_SELF_TYPE_HEADER SetMetricSamplingPercentage(
double percentage,
unsigned int seed =
sitkWallClock);
492 SITK_RETURN_SELF_TYPE_HEADER SetMetricSamplingPercentagePerLevel(
const std::vector<double> &percentage,
unsigned int seed =
sitkWallClock);
496 const std::vector<double> &GetMetricSamplingPercentagePerLevel()
const;
508 SITK_RETURN_SELF_TYPE_HEADER SetMetricSamplingStrategy( MetricSamplingStrategyType strategy);
519 SITK_RETURN_SELF_TYPE_HEADER SetMetricUseFixedImageGradientFilter(
bool);
535 SITK_RETURN_SELF_TYPE_HEADER SetMetricUseMovingImageGradientFilter(
bool);
548 SITK_RETURN_SELF_TYPE_HEADER SetShrinkFactorsPerLevel(
const std::vector<unsigned int> &shrinkFactors );
558 SITK_RETURN_SELF_TYPE_HEADER SetSmoothingSigmasPerLevel(
const std::vector<double> &smoothingSigmas );
566 SITK_RETURN_SELF_TYPE_HEADER SetSmoothingSigmasAreSpecifiedInPhysicalUnits(
bool arg);
585 double MetricEvaluate(
const Image &fixed,
const Image & moving );
594 unsigned int GetOptimizerIteration()
const;
595 std::vector<double> GetOptimizerPosition()
const;
596 double GetOptimizerLearningRate()
const;
597 double GetOptimizerConvergenceValue()
const;
598 double GetMetricValue()
const;
608 uint64_t GetMetricNumberOfValidPoints()
const;
611 unsigned int GetCurrentLevel()
const;
620 std::vector<double> GetOptimizerScales()
const;
624 std::string GetOptimizerStopConditionDescription()
const;
628 template<
class TImage>
631 template<
class TImage>
632 double EvaluateInternal (
const Image &fixed,
const Image &moving );
637 template<
unsigned int VDimension>
640 template <
class TImageType>
648 template <
class TImageType>
655 >*,
const TImageType*,
const TImageType* );
657 template <
typename TMetric>
660 template <
typename TTransformAdaptorPo
inter,
typename TRegistrationMethod >
661 std::vector< TTransformAdaptorPointer >
662 CreateTransformParametersAdaptor(
663 TRegistrationMethod* method);
666 void OnActiveProcessDelete( ) noexcept override;
668 void RemoveITKObserver( EventCommand &e ) override;
672 std::function<
unsigned int()> m_pfGetOptimizerIteration;
673 std::function<std::vector<
double>()> m_pfGetOptimizerPosition;
674 std::function<
double()> m_pfGetOptimizerLearningRate;
675 std::function<
double()> m_pfGetOptimizerConvergenceValue;
676 std::function<
double()> m_pfGetMetricValue;
677 std::function<
uint64_t()> m_pfGetMetricNumberOfValidPoints;
678 std::function<std::vector<
double>()> m_pfGetOptimizerScales;
679 std::function<std::
string()> m_pfGetOptimizerStopConditionDescription;
682 std::function<
unsigned int()> m_pfGetCurrentLevel;
686 template < class TMemberFunctionPointer >
689 using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
691 template<
typename TImageType >
692 TMemberFunctionPointer operator() ( )
const
694 return &ObjectType::template EvaluateInternal< TImageType >;
793 MattesMutualInformation
826 #endif // sitkImageRegistrationMethod_h