diff --git a/Examples/antsRegistration.cxx b/Examples/antsRegistration.cxx index e1a44eea0..2a09c1f31 100644 --- a/Examples/antsRegistration.cxx +++ b/Examples/antsRegistration.cxx @@ -309,7 +309,8 @@ antsRegistrationInitializeCommandLineOptions(itk::ants::CommandLineParser * pars std::string("one sample per voxel), otherwise it defines a point set over which to optimize the metric. ") + std::string("The point set can be on a regular lattice or a random lattice of points slightly ") + std::string("perturbed to minimize aliasing artifacts. samplingPercentage defines the ") + - std::string("fraction of points to select from the domain. ") + + std::string("fraction of points to select from the domain. useGradientFilter specifies whether a smoothing") + + std::string("filter is applied when estimating the metric gradient.") + std::string("In addition, three point set metrics are available: Euclidean ") + std::string("(ICP), Point-set expectation (PSE), and Jensen-Havrda-Charvet-Tsallis (JHCT)."); @@ -318,22 +319,22 @@ antsRegistrationInitializeCommandLineOptions(itk::ants::CommandLineParser * pars option->SetShortName('m'); option->SetUsageOption(0, "CC[fixedImage,movingImage,metricWeight,radius,,<" - "samplingPercentage=[0,1]>]"); + "samplingPercentage=[0,1]>,]"); option->SetUsageOption(1, "MI[fixedImage,movingImage,metricWeight,numberOfBins,,]"); + ">,,]"); option->SetUsageOption(2, "Mattes[fixedImage,movingImage,metricWeight,numberOfBins,,]"); + "Random}>,,]"); option->SetUsageOption(3, "MeanSquares[fixedImage,movingImage,metricWeight,radius=NA,,]"); + "Random}>,,]"); option->SetUsageOption(4, "Demons[fixedImage,movingImage,metricWeight,radius=NA,,]"); + "Random}>,,]"); option->SetUsageOption(5, "GC[fixedImage,movingImage,metricWeight,radius=NA,,<" - "samplingPercentage=[0,1]>]"); + "samplingPercentage=[0,1]>,]"); option->SetUsageOption( 6, "ICP[fixedPointSet,movingPointSet,metricWeight,,]"); option->SetUsageOption(7, diff --git a/Examples/antsRegistrationTemplateHeader.h b/Examples/antsRegistrationTemplateHeader.h index f00612975..b6b84dd85 100644 --- a/Examples/antsRegistrationTemplateHeader.h +++ b/Examples/antsRegistrationTemplateHeader.h @@ -973,6 +973,7 @@ DoRegistration(typename ParserType::Pointer & parser) typename RegistrationHelperType::SamplingStrategy samplingStrategy = RegistrationHelperType::none; unsigned int numberOfBins = 32; unsigned int radius = 4; + bool useGradientFilter = false; // assign default point-set variables @@ -993,6 +994,12 @@ DoRegistration(typename ParserType::Pointer & parser) { samplingPercentage = parser->Convert(metricOption->GetFunction(currentMetricNumber)->GetParameter(5)); } + + if (metricOption->GetFunction(currentMetricNumber)->GetNumberOfParameters() > 6) + { + useGradientFilter = parser->Convert(metricOption->GetFunction(currentMetricNumber)->GetParameter(6)); + } + std::string fixedFileName = metricOption->GetFunction(currentMetricNumber)->GetParameter(0); std::string movingFileName = metricOption->GetFunction(currentMetricNumber)->GetParameter(1); @@ -1196,6 +1203,7 @@ DoRegistration(typename ParserType::Pointer & parser) samplingStrategy, numberOfBins, radius, + useGradientFilter, useBoundaryPointsOnly, pointSetSigma, evaluationKNeighborhood, diff --git a/Examples/itkantsRegistrationHelper.h b/Examples/itkantsRegistrationHelper.h index 79c853ba7..ba4f8b238 100644 --- a/Examples/itkantsRegistrationHelper.h +++ b/Examples/itkantsRegistrationHelper.h @@ -208,6 +208,7 @@ class RegistrationHelper final : public itk::Object SamplingStrategy samplingStrategy, int numberOfBins, unsigned int radius, + bool useGradientFilter, bool useBoundaryPointsOnly, RealType pointSetSigma, unsigned int evaluationKNeighborhood, @@ -215,7 +216,8 @@ class RegistrationHelper final : public itk::Object bool useAnisotropicCovariances, RealType samplingPercentage, RealType intensityDistanceSigma, - RealType euclideanDistanceSigma) + RealType euclideanDistanceSigma + ) : m_MetricType(metricType) , m_FixedImage(fixedImage) , m_MovingImage(movingImage) @@ -224,6 +226,7 @@ class RegistrationHelper final : public itk::Object , m_SamplingStrategy(samplingStrategy) , m_NumberOfBins(numberOfBins) , m_Radius(radius) + , m_UseGradientFilter(useGradientFilter) , m_FixedLabeledPointSet(fixedLabeledPointSet) , m_MovingLabeledPointSet(movingLabeledPointSet) , m_FixedIntensityPointSet(fixedIntensityPointSet) @@ -302,6 +305,7 @@ class RegistrationHelper final : public itk::Object SamplingStrategy m_SamplingStrategy; int m_NumberOfBins; unsigned int m_Radius; // Only for CC metric + bool m_UseGradientFilter; // Variables for point-set metrics @@ -481,6 +485,7 @@ class RegistrationHelper final : public itk::Object SamplingStrategy samplingStrategy, int numberOfBins, unsigned int radius, + bool useGradientFilter, bool useBoundaryPointsOnly, RealType pointSetSigma, unsigned int evaluationKNeighborhood, @@ -500,6 +505,7 @@ class RegistrationHelper final : public itk::Object SamplingStrategy samplingStrategy, int numberOfBins, unsigned int radius, + bool useGradientFilter, RealType samplingPercentage) { this->AddMetric(metricType, @@ -514,6 +520,7 @@ class RegistrationHelper final : public itk::Object samplingStrategy, numberOfBins, radius, + useGradientFilter, false, 1.0, 50, diff --git a/Examples/itkantsRegistrationHelper.hxx b/Examples/itkantsRegistrationHelper.hxx index b152e21ad..73182eed4 100644 --- a/Examples/itkantsRegistrationHelper.hxx +++ b/Examples/itkantsRegistrationHelper.hxx @@ -258,6 +258,7 @@ RegistrationHelper::AddMetric(MetricEnumeration SamplingStrategy samplingStrategy, int numberOfBins, unsigned int radius, + bool useGradientFilter, bool useBoundaryPointsOnly, RealType pointSetSigma, unsigned int evaluationKNeighborhood, @@ -279,6 +280,7 @@ RegistrationHelper::AddMetric(MetricEnumeration samplingStrategy, numberOfBins, radius, + useGradientFilter, useBoundaryPointsOnly, pointSetSigma, evaluationKNeighborhood, @@ -783,8 +785,6 @@ template int RegistrationHelper::DoRegistration() { - /** Can really impact performance */ - const bool gradientfilter = false; itk::TimeProbe totalTimer; totalTimer.Start(); @@ -923,7 +923,9 @@ RegistrationHelper::DoRegistration() { const unsigned int radiusOption = stageMetricList[currentMetricNumber].m_Radius; this->Logger() << " using the CC metric (radius = " << radiusOption - << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting << ")" << std::endl; + << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter + << ")" << std::endl; typedef itk::ANTSNeighborhoodCorrelationImageToImageMetricv4 CorrelationMetricType; typename CorrelationMetricType::Pointer correlationMetric = CorrelationMetricType::New(); @@ -932,8 +934,6 @@ RegistrationHelper::DoRegistration() radius.Fill(radiusOption); correlationMetric->SetRadius(radius); } - correlationMetric->SetUseMovingImageGradientFilter(gradientfilter); - correlationMetric->SetUseFixedImageGradientFilter(gradientfilter); imageMetric = correlationMetric; } @@ -942,14 +942,14 @@ RegistrationHelper::DoRegistration() { const unsigned int binOption = stageMetricList[currentMetricNumber].m_NumberOfBins; this->Logger() << " using the Mattes MI metric (number of bins = " << binOption - << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting << ")" << std::endl; + << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter + << ")" << std::endl; typedef itk::MattesMutualInformationImageToImageMetricv4 MutualInformationMetricType; typename MutualInformationMetricType::Pointer mutualInformationMetric = MutualInformationMetricType::New(); // mutualInformationMetric = mutualInformationMetric; mutualInformationMetric->SetNumberOfHistogramBins(binOption); - mutualInformationMetric->SetUseMovingImageGradientFilter(gradientfilter); - mutualInformationMetric->SetUseFixedImageGradientFilter(gradientfilter); mutualInformationMetric->SetUseSampledPointSet(false); imageMetric = mutualInformationMetric; @@ -959,15 +959,15 @@ RegistrationHelper::DoRegistration() { const unsigned int binOption = stageMetricList[currentMetricNumber].m_NumberOfBins; this->Logger() << " using the joint histogram MI metric (number of bins = " << binOption - << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting << ")" << std::endl; + << ", weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter + << ")" << std::endl; typedef itk:: JointHistogramMutualInformationImageToImageMetricv4 MutualInformationMetricType; typename MutualInformationMetricType::Pointer mutualInformationMetric = MutualInformationMetricType::New(); // mutualInformationMetric = mutualInformationMetric; mutualInformationMetric->SetNumberOfHistogramBins(binOption); - mutualInformationMetric->SetUseMovingImageGradientFilter(gradientfilter); - mutualInformationMetric->SetUseFixedImageGradientFilter(gradientfilter); mutualInformationMetric->SetUseSampledPointSet(false); mutualInformationMetric->SetVarianceForJointPDFSmoothing(1.0); @@ -976,8 +976,10 @@ RegistrationHelper::DoRegistration() break; case MeanSquares: { - this->Logger() << " using the MeanSquares metric (weight = " - << stageMetricList[currentMetricNumber].m_Weighting << ")" << std::endl; + this->Logger() << " using the MeanSquares metric " + << "( weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter + << ")" << std::endl; typedef itk::MeanSquaresImageToImageMetricv4 MeanSquaresMetricType; @@ -989,7 +991,9 @@ RegistrationHelper::DoRegistration() break; case Demons: { - this->Logger() << " using the Demons metric (weight = " << stageMetricList[currentMetricNumber].m_Weighting + this->Logger() << " using the Demons metric " + << "( weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter << ")" << std::endl; typedef itk::DemonsImageToImageMetricv4 DemonsMetricType; @@ -1000,8 +1004,10 @@ RegistrationHelper::DoRegistration() break; case GC: { - this->Logger() << " using the global correlation metric (weight = " - << stageMetricList[currentMetricNumber].m_Weighting << ")" << std::endl; + this->Logger() << " using the global correlation metric " + << "( weight = " << stageMetricList[currentMetricNumber].m_Weighting + << ", use gradient filter = " << stageMetricList[currentMetricNumber].m_UseGradientFilter + << ")" << std::endl; typedef itk::CorrelationImageToImageMetricv4 corrMetricType; typename corrMetricType::Pointer corrMetric = corrMetricType::New(); @@ -1137,8 +1143,9 @@ RegistrationHelper::DoRegistration() // Set up the image metric and scales estimator imageMetric->SetVirtualDomainFromImage(fixedImage); - imageMetric->SetUseMovingImageGradientFilter(gradientfilter); - imageMetric->SetUseFixedImageGradientFilter(gradientfilter); + imageMetric->SetUseMovingImageGradientFilter(stageMetricList[currentMetricNumber].m_UseGradientFilter); + imageMetric->SetUseFixedImageGradientFilter(stageMetricList[currentMetricNumber].m_UseGradientFilter); + metricWeights[currentMetricNumber] = stageMetricList[currentMetricNumber].m_Weighting; if (useFixedImageMaskForThisStage) { diff --git a/Examples/simpleSynRegistration.cxx b/Examples/simpleSynRegistration.cxx index 5b755e7c9..04b59a2b1 100644 --- a/Examples/simpleSynRegistration.cxx +++ b/Examples/simpleSynRegistration.cxx @@ -75,7 +75,8 @@ simpleSynReg(ImageType::Pointer & fixedImage, constexpr float samplingPercentage = 1.0; RegistrationHelperType::SamplingStrategy samplingStrategy = RegistrationHelperType::none; constexpr unsigned int binOption = 200; - regHelper->AddMetric(curMetric, fixedImage, movingImage, 0, 1.0, samplingStrategy, binOption, 1, samplingPercentage); + bool useGradientFilter = false; + regHelper->AddMetric(curMetric, fixedImage, movingImage, 0, 1.0, samplingStrategy, binOption, 1, useGradientFilter, samplingPercentage); const float learningRate(0.25F); const float varianceForUpdateField(3.0F);