Medical image analysis toolkit providing algorithms for segmentation, registration, and processing of medical images
—
ITK's registration framework provides comprehensive algorithms for aligning and registering multiple image datasets. The framework follows a modular design with pluggable components for metrics, transforms, optimizers, and interpolators.
Main registration pipeline class that coordinates all registration components.
template<typename TFixedImage, typename TMovingImage>
class ImageRegistrationMethod : public ProcessObject
{
public:
typedef ImageRegistrationMethod Self;
typedef ProcessObject Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Input images
void SetFixedImage(const FixedImageType * fixedImage);
itkGetConstObjectMacro(FixedImage, FixedImageType);
void SetMovingImage(const MovingImageType * movingImage);
itkGetConstObjectMacro(MovingImage, MovingImageType);
// Registration components
void SetMetric(MetricType * metric);
itkGetObjectMacro(Metric, MetricType);
void SetOptimizer(OptimizerType * optimizer);
itkGetObjectMacro(Optimizer, OptimizerType);
void SetTransform(TransformType * transform);
itkGetObjectMacro(Transform, TransformType);
void SetInterpolator(InterpolatorType * interpolator);
itkGetObjectMacro(Interpolator, InterpolatorType);
// Region specification
void SetFixedImageRegion(const FixedImageRegionType & region);
itkGetConstReferenceMacro(FixedImageRegion, FixedImageRegionType);
// Initial parameters
void SetInitialTransformParameters(const ParametersType & param);
itkGetConstReferenceMacro(InitialTransformParameters, ParametersType);
// Results
itkGetConstReferenceMacro(LastTransformParameters, ParametersType);
// Execution
void StartRegistration();
virtual void Update() ITK_OVERRIDE;
};Multi-scale registration for improved robustness and speed.
template<typename TFixedImage, typename TMovingImage>
class MultiResolutionImageRegistrationMethod : public ImageRegistrationMethod<TFixedImage, TMovingImage>
{
public:
typedef MultiResolutionImageRegistrationMethod Self;
typedef ImageRegistrationMethod<TFixedImage, TMovingImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Pyramid generation
void SetFixedImagePyramid(FixedImagePyramidType * pyramid);
itkGetObjectMacro(FixedImagePyramid, FixedImagePyramidType);
void SetMovingImagePyramid(MovingImagePyramidType * pyramid);
itkGetObjectMacro(MovingImagePyramid, MovingImagePyramidType);
// Resolution levels
void SetNumberOfLevels(unsigned long numberOfLevels);
itkGetConstMacro(NumberOfLevels, unsigned long);
itkGetConstMacro(CurrentLevel, unsigned long);
// Schedule control
void SetSchedules(const ScheduleType & fixedImageSchedule,
const ScheduleType & movingImageSchedule);
void SetFixedImagePyramidSchedule(const ScheduleType & schedule);
void SetMovingImagePyramidSchedule(const ScheduleType & schedule);
itkGetConstReferenceMacro(FixedImagePyramidSchedule, ScheduleType);
itkGetConstReferenceMacro(MovingImagePyramidSchedule, ScheduleType);
};Base class for image similarity metrics.
template<typename TFixedImage, typename TMovingImage>
class ImageToImageMetric : public SingleValuedCostFunction
{
public:
typedef ImageToImageMetric Self;
typedef SingleValuedCostFunction Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
// Image inputs
void SetFixedImage(const FixedImageType * image);
itkGetConstObjectMacro(FixedImage, FixedImageType);
void SetMovingImage(const MovingImageType * image);
itkGetConstObjectMacro(MovingImage, MovingImageType);
// Transform and interpolator
void SetTransform(TransformType * transform);
itkGetObjectMacro(Transform, TransformType);
void SetInterpolator(InterpolatorType * interpolator);
itkGetObjectMacro(Interpolator, InterpolatorType);
// Region specification
void SetFixedImageRegion(const FixedImageRegionType & region);
itkGetConstReferenceMacro(FixedImageRegion, FixedImageRegionType);
// Sampling
void SetNumberOfSpatialSamples(unsigned long numberOfPixels);
itkGetConstMacro(NumberOfSpatialSamples, unsigned long);
// Evaluation methods
virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
virtual void GetDerivative(const ParametersType & parameters,
DerivativeType & derivative) const ITK_OVERRIDE;
virtual void GetValueAndDerivative(const ParametersType & parameters,
MeasureType & value,
DerivativeType & derivative) const ITK_OVERRIDE;
// Initialization
virtual void Initialize();
protected:
virtual void ComputeImageDerivatives(const MovingImagePointType & mappedPoint,
ImageDerivativesType & gradient,
ThreadIdType threadID) const;
};Mean squared differences similarity metric.
template<typename TFixedImage, typename TMovingImage>
class MeanSquaresImageToImageMetric : public ImageToImageMetric<TFixedImage, TMovingImage>
{
public:
typedef MeanSquaresImageToImageMetric Self;
typedef ImageToImageMetric<TFixedImage, TMovingImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Cost function evaluation
virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
virtual void GetDerivative(const ParametersType & parameters,
DerivativeType & derivative) const ITK_OVERRIDE;
virtual void GetValueAndDerivative(const ParametersType & parameters,
MeasureType & value,
DerivativeType & derivative) const ITK_OVERRIDE;
};Mutual information similarity metric for multi-modal registration.
template<typename TFixedImage, typename TMovingImage>
class MutualInformationImageToImageMetric : public ImageToImageMetric<TFixedImage, TMovingImage>
{
public:
typedef MutualInformationImageToImageMetric Self;
typedef ImageToImageMetric<TFixedImage, TMovingImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Histogram parameters
void SetNumberOfSpatialSamples(unsigned long numberOfSamples);
void SetFixedImageStandardDeviation(double standardDeviation);
void SetMovingImageStandardDeviation(double standardDeviation);
itkGetConstMacro(FixedImageStandardDeviation, double);
itkGetConstMacro(MovingImageStandardDeviation, double);
// Kernel function
void SetKernelFunction(KernelFunctionType * kernelFunction);
itkGetObjectMacro(KernelFunction, KernelFunctionType);
// Cost function evaluation
virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
virtual void GetDerivative(const ParametersType & parameters,
DerivativeType & derivative) const ITK_OVERRIDE;
virtual void GetValueAndDerivative(const ParametersType & parameters,
MeasureType & value,
DerivativeType & derivative) const ITK_OVERRIDE;
};Normalized correlation similarity metric.
template<typename TFixedImage, typename TMovingImage>
class NormalizedCorrelationImageToImageMetric : public ImageToImageMetric<TFixedImage, TMovingImage>
{
public:
typedef NormalizedCorrelationImageToImageMetric Self;
typedef ImageToImageMetric<TFixedImage, TMovingImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Intensity scaling
void SetSubtractMean(bool subtractMean);
itkGetConstMacro(SubtractMean, bool);
// Cost function evaluation
virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
virtual void GetDerivative(const ParametersType & parameters,
DerivativeType & derivative) const ITK_OVERRIDE;
virtual void GetValueAndDerivative(const ParametersType & parameters,
MeasureType & value,
DerivativeType & derivative) const ITK_OVERRIDE;
};Base class for geometric transformations.
template<typename TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
class Transform : public TransformBase
{
public:
typedef Transform Self;
typedef TransformBase Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
// Point transformation
virtual OutputPointType TransformPoint(const InputPointType & point) const = 0;
virtual OutputVectorType TransformVector(const InputVectorType & vector) const;
virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & vector) const;
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & vector) const;
// Jacobian computation
virtual const JacobianType & GetJacobian(const InputPointType & point) const;
// Parameters
virtual void SetParameters(const ParametersType & parameters);
virtual const ParametersType & GetParameters() const;
virtual void SetFixedParameters(const ParametersType & parameters);
virtual const ParametersType & GetFixedParameters() const;
virtual unsigned int GetNumberOfParameters() const;
// Transform composition
virtual bool IsLinear() const;
virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE;
};Linear transformation including rotation, scaling, shearing, and translation.
template<typename TScalarType, unsigned int NDimensions>
class AffineTransform : public MatrixOffsetTransformBase<TScalarType, NDimensions, NDimensions>
{
public:
typedef AffineTransform Self;
typedef MatrixOffsetTransformBase<TScalarType, NDimensions, NDimensions> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Matrix and offset access
virtual void SetMatrix(const MatrixType & matrix);
const MatrixType & GetMatrix() const;
virtual void SetOffset(const OutputVectorType & offset);
const OutputVectorType & GetOffset() const;
// Transformation operations
void SetIdentity();
void Translate(const OutputVectorType & offset, bool pre = false);
void Scale(const OutputVectorType & factor, bool pre = false);
void Scale(const TScalarType & factor, bool pre = false);
void Rotate2D(TScalarType angle, bool pre = false);
void Rotate3D(const OutputVectorType & axis, TScalarType angle, bool pre = false);
void Shear(int axis1, int axis2, TScalarType coeff, bool pre = false);
// Inverse transformation
bool GetInverse(Self * inverse) const;
InverseTransformBasePointer GetInverseTransform() const ITK_OVERRIDE;
};B-spline deformable transformation for non-rigid registration.
template<typename TScalarType, unsigned int NDimensions, unsigned int VSplineOrder>
class BSplineTransform : public Transform<TScalarType, NDimensions, NDimensions>
{
public:
typedef BSplineTransform Self;
typedef Transform<TScalarType, NDimensions, NDimensions> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Grid specification
virtual void SetGridRegion(const RegionType & region);
itkGetConstMacro(GridRegion, RegionType);
virtual void SetGridSpacing(const SpacingType & spacing);
itkGetConstMacro(GridSpacing, SpacingType);
virtual void SetGridOrigin(const OriginType & origin);
itkGetConstMacro(GridOrigin, OriginType);
virtual void SetGridDirection(const DirectionType & direction);
itkGetConstMacro(GridDirection, DirectionType);
// Bulk transform
void SetBulkTransform(const BulkTransformType * bulkTransform);
itkGetConstObjectMacro(BulkTransform, BulkTransformType);
// Coefficient images
virtual void SetCoefficientImages(const CoefficientImageArray & images);
const CoefficientImageArray GetCoefficientImages() const;
// Point transformation
virtual OutputPointType TransformPoint(const InputPointType & point) const ITK_OVERRIDE;
virtual void TransformPoint(const InputPointType & inputPoint,
OutputPointType & outputPoint,
WeightsType & weights,
ParameterIndexArrayType & indices,
bool & inside) const;
// Jacobian computation
virtual const JacobianType & GetJacobian(const InputPointType & point) const ITK_OVERRIDE;
virtual void ComputeJacobianWithRespectToParameters(const InputPointType & point,
JacobianType & jacobian) const ITK_OVERRIDE;
};Base class for image interpolation.
template<typename TInputImage, typename TCoordRep>
class InterpolateImageFunction : public ImageFunction<TInputImage, typename TInputImage::PixelType, TCoordRep>
{
public:
typedef InterpolateImageFunction Self;
typedef ImageFunction<TInputImage, typename TInputImage::PixelType, TCoordRep> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
// Interpolation methods
virtual OutputType Evaluate(const PointType & point) const ITK_OVERRIDE = 0;
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index) const = 0;
// Bounds checking
virtual bool IsInsideBuffer(const PointType & point) const;
virtual bool IsInsideBuffer(const ContinuousIndexType & index) const;
};Linear interpolation of image values.
template<typename TInputImage, typename TCoordRep>
class LinearInterpolateImageFunction : public InterpolateImageFunction<TInputImage, TCoordRep>
{
public:
typedef LinearInterpolateImageFunction Self;
typedef InterpolateImageFunction<TInputImage, TCoordRep> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Interpolation methods
virtual OutputType Evaluate(const PointType & point) const ITK_OVERRIDE;
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index) const ITK_OVERRIDE;
// Derivative computation
CovariantVectorType EvaluateDerivative(const PointType & point) const;
CovariantVectorType EvaluateDerivativeAtContinuousIndex(const ContinuousIndexType & index) const;
};B-spline interpolation for smooth image resampling.
template<typename TImageType, typename TCoordRep, typename TCoefficientType>
class BSplineInterpolateImageFunction : public InterpolateImageFunction<TImageType, TCoordRep>
{
public:
typedef BSplineInterpolateImageFunction Self;
typedef InterpolateImageFunction<TImageType, TCoordRep> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Spline order
void SetSplineOrder(unsigned int splineOrder);
itkGetConstMacro(SplineOrder, int);
// Interpolation methods
virtual OutputType Evaluate(const PointType & point) const ITK_OVERRIDE;
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index) const ITK_OVERRIDE;
// Derivative computation
CovariantVectorType EvaluateDerivative(const PointType & point) const;
CovariantVectorType EvaluateDerivativeAtContinuousIndex(const ContinuousIndexType & index) const;
// Higher-order derivatives
void EvaluateValueAndDerivative(const PointType & point,
OutputType & value,
CovariantVectorType & derivative) const;
};Generates multi-resolution image pyramids.
template<typename TInputImage, typename TOutputImage>
class RecursiveMultiResolutionPyramidImageFilter : public MultiResolutionPyramidImageFilter<TInputImage, TOutputImage>
{
public:
typedef RecursiveMultiResolutionPyramidImageFilter Self;
typedef MultiResolutionPyramidImageFilter<TInputImage, TOutputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Pyramid generation parameters
virtual void SetNumberOfLevels(unsigned int num) ITK_OVERRIDE;
void SetSchedule(const ScheduleType & schedule);
itkGetConstReferenceMacro(Schedule, ScheduleType);
// Smoothing control
virtual void SetUseShrinkImageFilter(bool useShrinkFilter);
itkGetConstMacro(UseShrinkImageFilter, bool);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void GenerateOutputInformation() ITK_OVERRIDE;
virtual void GenerateOutputRequestedRegion(DataObject * output) ITK_OVERRIDE;
};// Define image types
typedef itk::Image<float, 2> FixedImageType;
typedef itk::Image<float, 2> MovingImageType;
// Registration method
typedef itk::ImageRegistrationMethod<FixedImageType, MovingImageType> RegistrationType;
RegistrationType::Pointer registration = RegistrationType::New();
// Transform
typedef itk::TranslationTransform<double, 2> TransformType;
TransformType::Pointer transform = TransformType::New();
registration->SetTransform(transform);
// Metric
typedef itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType> MetricType;
MetricType::Pointer metric = MetricType::New();
registration->SetMetric(metric);
// Optimizer
typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
OptimizerType::Pointer optimizer = OptimizerType::New();
registration->SetOptimizer(optimizer);
// Interpolator
typedef itk::LinearInterpolateImageFunction<MovingImageType, double> InterpolatorType;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
registration->SetInterpolator(interpolator);
// Set images
registration->SetFixedImage(fixedImage);
registration->SetMovingImage(movingImage);
registration->SetFixedImageRegion(fixedImage->GetBufferedRegion());
// Initialize parameters
TransformType::ParametersType initialParameters(transform->GetNumberOfParameters());
initialParameters[0] = 0.0; // Initial offset in X
initialParameters[1] = 0.0; // Initial offset in Y
registration->SetInitialTransformParameters(initialParameters);
// Configure optimizer
optimizer->SetMaximumStepLength(4.00);
optimizer->SetMinimumStepLength(0.01);
optimizer->SetNumberOfIterations(200);
// Run registration
try {
registration->Update();
TransformType::ParametersType finalParameters = registration->GetLastTransformParameters();
} catch (itk::ExceptionObject & err) {
std::cerr << "Registration failed: " << err << std::endl;
}// Common registration instantiations
typedef ImageRegistrationMethod<Image<float,2>, Image<float,2>> Registration2D;
typedef ImageRegistrationMethod<Image<float,3>, Image<float,3>> Registration3D;
typedef MultiResolutionImageRegistrationMethod<Image<float,2>, Image<float,2>> MultiResRegistration2D;
typedef MultiResolutionImageRegistrationMethod<Image<float,3>, Image<float,3>> MultiResRegistration3D;
// Transform types
typedef TranslationTransform<double, 2> Translation2D;
typedef TranslationTransform<double, 3> Translation3D;
typedef AffineTransform<double, 2> Affine2D;
typedef AffineTransform<double, 3> Affine3D;
// Metric types
typedef MeanSquaresImageToImageMetric<Image<float,2>, Image<float,2>> MSMetric2D;
typedef MutualInformationImageToImageMetric<Image<float,2>, Image<float,2>> MIMetric2D;
typedef NormalizedCorrelationImageToImageMetric<Image<float,2>, Image<float,2>> NCMetric2D;
// Interpolator types
typedef LinearInterpolateImageFunction<Image<float,2>, double> LinearInterpolator2D;
typedef BSplineInterpolateImageFunction<Image<float,2>, double> BSplineInterpolator2D;
typedef NearestNeighborInterpolateImageFunction<Image<float,2>, double> NNInterpolator2D;
// Parameter and schedule types
typedef OptimizerType::ParametersType ParametersType;
typedef OptimizerType::ScalesType OptimizerScalesType;
typedef MultiResolutionPyramidImageFilter<Image<float,2>, Image<float,2>>::ScheduleType ScheduleType;ITK's registration framework provides a comprehensive, modular approach to image alignment with support for rigid, affine, and deformable transformations across multiple scales and with various similarity metrics.
Install with Tessl CLI
npx tessl i tessl/cmake-itk