SimpleITK  
ImageRegistrationOptimizerWeights/ImageRegistrationOptimizerWeights.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include <SimpleITK.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
namespace sitk = itk::simple;
int
main(int argc, char * argv[])
{
using sitk::operator<<;
if (argc < 4)
{
std::cout << "Usage: " << argv[0] << " <fixedImageFile> <movingImageFile> <outputTransformFile>" << std::endl;
return 1;
}
sitk::Image fixedImage = sitk::ReadImage(argv[1], sitk::sitkFloat32);
sitk::Image movingImage = sitk::ReadImage(argv[2], sitk::sitkFloat32);
// initialization
// registration
sitk::ImageRegistrationMethod registrationMethod;
registrationMethod.SetMetricAsCorrelation();
registrationMethod.SetMetricSamplingStrategy(registrationMethod.NONE);
registrationMethod.SetInterpolator(sitk::sitkLinear);
registrationMethod.SetOptimizerAsGradientDescent(1.0, // learningRate
300, // numberOfIterations
1e-6, // convergenceMinimumValue
10); // convergenceWindowSize
registrationMethod.SetInitialTransform(transform, true); // inPlace=true
// Set optimizer weights: [0, 0, 1, 1, 1, 1] - disable rotation around x and y axes
std::vector<double> weights = { 0, 0, 1, 1, 1, 1 };
registrationMethod.SetOptimizerWeights(weights);
registrationMethod.Execute(fixedImage, movingImage);
std::cout << "-------" << std::endl;
std::cout << "Final transform parameters: " << transform.GetParameters() << std::endl;
std::cout << "Optimizer stop condition: " << registrationMethod.GetOptimizerStopConditionDescription() << std::endl;
std::cout << "Iteration: " << registrationMethod.GetOptimizerIteration() << std::endl;
std::cout << "Metric value: " << registrationMethod.GetMetricValue() << std::endl;
sitk::WriteTransform(transform, argv[3]);
return 0;
}
A rigid 3D transform with rotation in radians around a fixed center with translation.
An interface method to the modular ITKv4 registration framework.
void SetMetricAsCorrelation()
Use negative normalized cross correlation image metric.
void SetOptimizerWeights(const std::vector< double > &weights)
A per parameter weighting array for the optimizer.
void SetMetricSamplingStrategy(MetricSamplingStrategyType strategy)
Set sampling strategy for sample generation.
void SetInterpolator(InterpolatorEnum Interpolator)
Set and get the interpolator to use.
Transform Execute(const Image &fixed, const Image &moving)
Optimize the configured registration problem.
std::string GetOptimizerStopConditionDescription() const
void SetOptimizerAsGradientDescent(double learningRate, unsigned int numberOfIterations, double convergenceMinimumValue=1e-6, unsigned int convergenceWindowSize=10, EstimateLearningRateType estimateLearningRate=Once, double maximumStepSizeInPhysicalUnits=0.0)
Gradient descent optimizer.
void SetOptimizerScalesFromPhysicalShift(unsigned int centralRegionRadius=5, double smallParameterVariation=0.01)
Estimating scales of transform parameters a step sizes, from the maximum voxel shift in physical spac...
unsigned int GetOptimizerIteration() const
void SetInitialTransform(const Transform &transform)
Set the initial transform and parameters to optimize.
The Image class for SimpleITK.
Definition sitkImage.h:77
A simplified wrapper around a variety of ITK transforms.
std::vector< double > GetParameters() const
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
@ sitkLinear
N-D linear interpolation.
Transform CenteredTransformInitializer(const Image &fixedImage, const Image &movingImage, const Transform &transform, CenteredTransformInitializerFilter::OperationModeType operationMode=itk::simple::CenteredTransformInitializerFilter::MOMENTS)
CenteredTransformInitializer is a helper class intended to initialize the center of rotation and the ...
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const PathType &filename)