SimpleITK  
ImageRegistrationOptimizerWeights/ImageRegistrationOptimizerWeights.cs
/*=========================================================================
*
* 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.
*
*=========================================================================*/
using System;
using itk.simple;
namespace itk.simple.examples
{
class ImageRegistrationOptimizerWeights
{
static void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("Usage: ImageRegistrationOptimizerWeights <fixedImageFile> <movingImageFile> <outputTransformFile>");
return;
}
Image fixedImage = SimpleITK.ReadImage(args[0], PixelIDValueEnum.sitkFloat32);
Image movingImage = SimpleITK.ReadImage(args[1], PixelIDValueEnum.sitkFloat32);
// initialization
Transform transform = SimpleITK.CenteredTransformInitializer(
fixedImage,
movingImage,
// registration
registrationMethod.SetMetricAsCorrelation();
registrationMethod.SetInterpolator(InterpolatorEnum.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
VectorDouble weights = new VectorDouble(new double[] { 0, 0, 1, 1, 1, 1 });
registrationMethod.SetOptimizerWeights(weights);
registrationMethod.Execute(fixedImage, movingImage);
Console.WriteLine("-------");
Console.WriteLine("Final transform parameters: " + transform.GetParameters());
Console.WriteLine("Optimizer stop condition: " + registrationMethod.GetOptimizerStopConditionDescription());
Console.WriteLine("Iteration: " + registrationMethod.GetOptimizerIteration());
Console.WriteLine("Metric value: " + registrationMethod.GetMetricValue());
SimpleITK.WriteTransform(transform, args[2]);
}
}
}
CenteredTransformInitializerFilter is a helper class intended to initialize the center of rotation an...
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
MetricSamplingStrategyType
Sampling strategies for obtaining points.
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.
void WriteTransform(const std::string &filename) const
std::vector< double > GetParameters() const
PixelIDValueEnum
Enumerated values of pixelIDs.