SimpleITK  
ImageRegistrationMethod1/ImageRegistrationMethod1.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 IterationUpdate : Command {
private ImageRegistrationMethod m_Method;
public IterationUpdate(ImageRegistrationMethod m) {
m_Method=m;
}
public override void Execute() {
VectorDouble pos = m_Method.GetOptimizerPosition();
Console.WriteLine("{0:3} = {1:10.5} : [{2}, {3}]",
m_Method.GetMetricValue(),
pos[0], pos[1]);
}
}
class ImageRegistrationMethod1 {
static void Main(string[] args) {
if ( args.Length < 3 )
{
Console.WriteLine("Usage: %s <fixedImageFilter> <movingImageFile> <outputTransformFile>\n", "ImageRegistrationMethod1");
return;
}
reader.SetOutputPixelType( PixelIDValueEnum.sitkFloat32 );
reader.SetFileName(args[0]);
Image fixedImage = reader.Execute();
reader.SetFileName(args[1]);
Image movingImage = reader.Execute();
double maxStep = 4.0;
double minStep = 0.01;
uint numberOfIterations = 200;
double relaxationFactor = 0.5;
minStep,
numberOfIterations,
relaxationFactor );
IterationUpdate cmd = new IterationUpdate(R);
R.AddCommand(EventEnum.sitkIterationEvent, cmd);
Transform outTx = R.Execute( fixedImage, movingImage );
// System.out.println("-------");
// System.out.println(outTx.toString());
// System.out.format("Optimizer stop condition: %s\n", R.getOptimizerStopConditionDescription());
// System.out.format(" Iteration: %d\n", R.getOptimizerIteration());
// System.out.format(" Metric value: %f\n", R.getMetricValue());
outTx.WriteTransform(args[2]);
}
}
}
An implementation of the Command design pattern for callback.
Definition sitkCommand.h:45
Read an image file and return a SimpleITK Image.
Image Execute() override
Set/Get The output PixelType of the image.
Self & SetFileName(const PathType &fn)
Self & SetOutputPixelType(PixelIDValueEnum pixelID)
Set/Get The output PixelType of the image.
An interface method to the modular ITKv4 registration framework.
Self & SetInterpolator(InterpolatorEnum Interpolator)
Set and get the interpolator to use.
Transform Execute(const Image &fixed, const Image &moving)
Optimize the configured registration problem.
std::vector< double > GetOptimizerPosition() const
Self & SetOptimizerAsRegularStepGradientDescent(double learningRate, double minStep, unsigned int numberOfIterations, double relaxationFactor=0.5, double gradientMagnitudeTolerance=1e-4, EstimateLearningRateType estimateLearningRate=Never, double maximumStepSizeInPhysicalUnits=0.0)
Regular Step Gradient descent optimizer.
Self & SetMetricAsMeanSquares()
Use negative means squares image metric.
unsigned int GetOptimizerIteration() const
Self & SetInitialTransform(const Transform &transform)
Set the initial transform and parameters to optimize.
The Image class for SimpleITK.
Definition sitkImage.h:77
unsigned int GetDimension() const
virtual int AddCommand(itk::simple::EventEnum event, itk::simple::Command &cmd)
Add a Command Object to observer the event.
A simplified wrapper around a variety of ITK transforms.
void WriteTransform(const std::string &filename) const
Translation of a 2D or 3D coordinate space.
EventEnum
Events which can be observed from ProcessObject.
Definition sitkEvent.h:32
PixelIDValueEnum
Enumerated values of pixelIDs.