CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/cmake-itk

Medical image analysis toolkit providing algorithms for segmentation, registration, and processing of medical images

Pending
Overview
Eval results
Files

mathematical-operations.mddocs/

Mathematical Operations

ITK provides comprehensive mathematical algorithms including optimization, statistics, numerical analysis, and linear algebra operations. These components support advanced image analysis, registration, and machine learning applications.

Optimization Framework

Optimizer

Base class for all optimization algorithms.

class Optimizer : public Object
{
public:
    typedef Optimizer                         Self;
    typedef Object                            Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    // Parameters
    typedef Array<double>                     ParametersType;
    typedef Array<double>                     ScalesType;
    
    // Optimization control
    virtual void StartOptimization() = 0;
    virtual void StopOptimization();
    virtual bool CanUseScales() const;
    
    // Parameters
    virtual void SetInitialPosition(const ParametersType & param);
    itkGetConstReferenceMacro(InitialPosition, ParametersType);
    virtual const ParametersType & GetCurrentPosition() const;
    
    // Scaling
    void SetScales(const ScalesType & scales);
    const ScalesType & GetScales() const;
    const ScalesType & GetInverseScales() const;
    
    // Observer pattern
    void AddObserver(const EventObject & event, Command * command);
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

SingleValuedNonLinearOptimizer

Base class for single-valued cost function optimizers.

class SingleValuedNonLinearOptimizer : public Optimizer
{
public:
    typedef SingleValuedNonLinearOptimizer    Self;
    typedef Optimizer                         Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    // Cost function types
    typedef SingleValuedCostFunction          CostFunctionType;
    typedef CostFunctionType::Pointer         CostFunctionPointer;
    typedef CostFunctionType::MeasureType     MeasureType;
    typedef CostFunctionType::DerivativeType  DerivativeType;
    
    // Cost function
    virtual void SetCostFunction(CostFunctionType * costFunction);
    itkGetObjectMacro(CostFunction, CostFunctionType);
    
    // Results
    itkGetConstReferenceMacro(Value, MeasureType);
    itkGetConstReferenceMacro(Gradient, DerivativeType);
    
    // Optimization status
    virtual const std::string GetStopConditionDescription() const;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

GradientDescentOptimizer

Gradient descent optimization algorithm.

class GradientDescentOptimizer : public SingleValuedNonLinearOptimizer
{
public:
    typedef GradientDescentOptimizer          Self;
    typedef SingleValuedNonLinearOptimizer    Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Optimization parameters
    void SetLearningRate(double learningRate);
    itkGetConstMacro(LearningRate, double);
    
    void SetNumberOfIterations(unsigned long numberOfIterations);
    itkGetConstMacro(NumberOfIterations, unsigned long);
    
    // Current iteration
    itkGetConstMacro(CurrentIteration, unsigned int);
    
    // Convergence monitoring
    void SetMaximize(bool maximize);
    itkGetConstMacro(Maximize, bool);
    void MaximizeOn() { SetMaximize(true); }
    void MaximizeOff() { SetMaximize(false); }
    
    // Optimization execution
    virtual void StartOptimization() ITK_OVERRIDE;
    virtual void ResumeOptimization();
    virtual void StopOptimization() ITK_OVERRIDE;
    
    // Results
    virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
    virtual void AdvanceOneStep();
};

RegularStepGradientDescentOptimizer

Gradient descent with adaptive step size.

class RegularStepGradientDescentOptimizer : public SingleValuedNonLinearOptimizer
{
public:
    typedef RegularStepGradientDescentOptimizer Self;
    typedef SingleValuedNonLinearOptimizer    Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Step size control
    void SetMaximumStepLength(double maximumStepLength);
    void SetMinimumStepLength(double minimumStepLength);
    itkGetConstMacro(MaximumStepLength, double);
    itkGetConstMacro(MinimumStepLength, double);
    
    // Current step length
    itkGetConstMacro(CurrentStepLength, double);
    
    // Relaxation factor
    void SetRelaxationFactor(double relaxationFactor);
    itkGetConstMacro(RelaxationFactor, double);
    
    // Gradient magnitude tolerance
    void SetGradientMagnitudeTolerance(double gradientMagnitudeTolerance);
    itkGetConstMacro(GradientMagnitudeTolerance, double);
    
    // Iteration control
    void SetNumberOfIterations(unsigned long numberOfIterations);
    itkGetConstMacro(NumberOfIterations, unsigned long);
    itkGetConstMacro(CurrentIteration, unsigned int);
    
    // Convergence value
    void SetValue(double value);
    itkGetConstMacro(Value, double);
    
    // Maximize/minimize
    void SetMaximize(bool maximize);
    itkGetConstMacro(Maximize, bool);
    void MaximizeOn() { SetMaximize(true); }
    void MaximizeOff() { SetMaximize(false); }
    
    // Optimization execution
    virtual void StartOptimization() ITK_OVERRIDE;
    virtual void ResumeOptimization();
    virtual void StopOptimization() ITK_OVERRIDE;
    
    // Results
    virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

LBFGSOptimizer

Limited-memory BFGS quasi-Newton optimization.

class LBFGSOptimizer : public SingleValuedNonLinearOptimizer
{
public:
    typedef LBFGSOptimizer                    Self;
    typedef SingleValuedNonLinearOptimizer    Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // LBFGS parameters
    void SetTrace(bool trace);
    itkGetConstMacro(Trace, bool);
    
    void SetMaximumNumberOfFunctionEvaluations(unsigned int maximumNumberOfFunctionEvaluations);
    itkGetConstMacro(MaximumNumberOfFunctionEvaluations, unsigned int);
    
    void SetGradientConvergenceTolerance(double gradientConvergenceTolerance);
    itkGetConstMacro(GradientConvergenceTolerance, double);
    
    void SetLineSearchAccuracy(double lineSearchAccuracy);
    itkGetConstMacro(LineSearchAccuracy, double);
    
    void SetDefaultStepLength(double defaultStepLength);
    itkGetConstMacro(DefaultStepLength, double);
    
    // Optimization execution
    virtual void StartOptimization() ITK_OVERRIDE;
    
    // Results
    virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
    
    // Memory size
    void SetMaximumNumberOfCorrections(unsigned int maximumNumberOfCorrections);
    itkGetConstMacro(MaximumNumberOfCorrections, unsigned int);
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

AmoebaOptimizer

Nelder-Mead simplex (Amoeba) optimization.

class AmoebaOptimizer : public SingleValuedNonLinearOptimizer
{
public:
    typedef AmoebaOptimizer                   Self;
    typedef SingleValuedNonLinearOptimizer    Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Simplex parameters
    void SetMaximumNumberOfIterations(unsigned int maximumNumberOfIterations);
    itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
    
    void SetAutomaticInitialSimplex(bool automaticInitialSimples);
    itkGetConstMacro(AutomaticInitialSimplex, bool);
    
    void SetOptimizeWithRestarts(bool optimizeWithRestarts);
    itkGetConstMacro(OptimizeWithRestarts, bool);
    
    // Tolerance settings
    void SetParametersConvergenceTolerance(double parametersConvergenceTolerance);
    itkGetConstMacro(ParametersConvergenceTolerance, double);
    
    void SetFunctionConvergenceTolerance(double functionConvergenceTolerance);
    itkGetConstMacro(FunctionConvergenceTolerance, double);
    
    // Initial simplex
    void SetInitialSimplexDelta(ParametersType initialSimplexDelta, bool automaticInitialSimplex = false);
    itkGetConstMacro(InitialSimplexDelta, ParametersType);
    
    // Optimization execution
    virtual void StartOptimization() ITK_OVERRIDE;
    
    // Results
    virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

Statistics Framework

Sample

Base interface for statistical samples.

template<typename TMeasurementVector>
class Sample : public DataObject
{
public:
    typedef Sample                            Self;
    typedef DataObject                        Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    // Measurement vector types
    typedef TMeasurementVector                MeasurementVectorType;
    typedef typename MeasurementVectorType::ValueType MeasurementType;
    
    // Sample size
    virtual InstanceIdentifier Size() const = 0;
    virtual unsigned int GetMeasurementVectorSize() const = 0;
    
    // Data access
    virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const = 0;
    virtual MeasurementType GetMeasurement(InstanceIdentifier id, unsigned int dimension);
    
    // Frequency information
    virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const = 0;
    virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
    
    // Iteration support
    virtual void Graft(const DataObject * thatObject) ITK_OVERRIDE;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

ListSample

Sample implementation using STL list container.

template<typename TMeasurementVector>
class ListSample : public Sample<TMeasurementVector>
{
public:
    typedef ListSample                        Self;
    typedef Sample<TMeasurementVector>       Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Container types
    typedef std::vector<MeasurementVectorType> InternalDataContainerType;
    typedef std::vector<AbsoluteFrequencyType> AbsoluteFrequencyContainerType;
    
    // Sample modification
    void PushBack(const MeasurementVectorType & measurementVector);
    void Resize(InstanceIdentifier newSize);
    void Clear();
    
    // Sample size
    virtual InstanceIdentifier Size() const ITK_OVERRIDE;
    virtual unsigned int GetMeasurementVectorSize() const ITK_OVERRIDE;
    void SetMeasurementVectorSize(unsigned int s);
    
    // Data access
    virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
    void SetMeasurementVector(InstanceIdentifier id, const MeasurementVectorType & measurementVector);
    void SetMeasurement(InstanceIdentifier id, unsigned int dimension, const MeasurementType & value);
    
    // Frequency information
    virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const ITK_OVERRIDE;
    void SetFrequency(InstanceIdentifier id, AbsoluteFrequencyType frequency);
    virtual TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
    
    // Iteration
    class Iterator;
    class ConstIterator;
    Iterator Begin();
    Iterator End();
    ConstIterator Begin() const;
    ConstIterator End() const;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

Histogram

Multi-dimensional histogram for statistical analysis.

template<typename TMeasurement, unsigned int VMeasurementVectorSize>
class Histogram : public Sample<FixedArray<TMeasurement, VMeasurementVectorSize>>
{
public:
    typedef Histogram                         Self;
    typedef Sample<FixedArray<TMeasurement, VMeasurementVectorSize>> Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Histogram bin types
    typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
    typedef typename Superclass::MeasurementType       MeasurementType;
    typedef typename Superclass::InstanceIdentifier    InstanceIdentifier;
    typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
    typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
    
    typedef MeasurementVectorType                       BinMinVectorType;
    typedef MeasurementVectorType                       BinMaxVectorType;
    typedef std::vector<MeasurementType>               BinMinContainerType;
    typedef std::vector<MeasurementType>               BinMaxContainerType;
    
    // Initialization
    void Initialize(const SizeType & size);
    void Initialize(const SizeType & size, const BinMinVectorType & lowerBound, const BinMaxVectorType & upperBound);
    
    // Size information
    virtual InstanceIdentifier Size() const ITK_OVERRIDE;
    SizeType GetSize() const;
    SizeValueType GetSize(unsigned int dimension) const;
    
    // Bin boundaries
    const BinMinVectorType & GetBinMin(unsigned int dimension, InstanceIdentifier binIndex) const;
    const BinMaxVectorType & GetBinMax(unsigned int dimension, InstanceIdentifier binIndex) const;
    
    // Frequency access
    virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const ITK_OVERRIDE;
    bool SetFrequency(InstanceIdentifier id, AbsoluteFrequencyType frequency);
    bool IncreaseFrequency(InstanceIdentifier id, AbsoluteFrequencyType frequency);
    
    // Bin index calculations
    bool GetIndex(const MeasurementVectorType & measurement, IndexType & index) const;
    InstanceIdentifier GetInstanceIdentifier(const IndexType & index) const;
    
    // Statistics
    double GetMean(unsigned int dimension) const;
    double GetVariance(unsigned int dimension) const;
    
    // Quantiles
    double Quantile(unsigned int dimension, double percent) const;
    
    // Iteration
    class Iterator;
    class ConstIterator;
    Iterator Begin();
    Iterator End();
    ConstIterator Begin() const;
    ConstIterator End() const;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

MembershipFunction

Base class for membership functions in statistical classification.

template<typename TVector>
class MembershipFunction : public FunctionBase<TVector, double>
{
public:
    typedef MembershipFunction                Self;
    typedef FunctionBase<TVector, double>    Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    // Function evaluation
    virtual double Evaluate(const MeasurementVectorType & measurement) const = 0;
    
    // Measurement vector dimension
    void SetMeasurementVectorSize(unsigned int measurementVectorSize);
    unsigned int GetMeasurementVectorSize() const;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};

GaussianMembershipFunction

Multivariate Gaussian membership function.

template<typename TVector>
class GaussianMembershipFunction : public MembershipFunction<TVector>
{
public:
    typedef GaussianMembershipFunction        Self;
    typedef MembershipFunction<TVector>      Superclass;
    typedef SmartPointer<Self>               Pointer;
    typedef SmartPointer<const Self>         ConstPointer;
    
    static Pointer New();
    
    // Parameters
    typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
    typedef vnl_vector<double>               MeanVectorType;
    typedef vnl_matrix<double>               CovarianceMatrixType;
    
    // Mean vector
    void SetMean(const MeanVectorType & mean);
    void SetMean(const MeasurementVectorType & mean);
    itkGetConstReferenceMacro(Mean, MeanVectorType);
    
    // Covariance matrix
    void SetCovariance(const CovarianceMatrixType & covariance);
    itkGetConstReferenceMacro(Covariance, CovarianceMatrixType);
    
    // Inverse covariance matrix
    void SetInverseCovariance(const CovarianceMatrixType & inverseCovariance);
    itkGetConstReferenceMacro(InverseCovariance, CovarianceMatrixType);
    
    // Function evaluation
    virtual double Evaluate(const MeasurementVectorType & measurement) const ITK_OVERRIDE;
    
protected:
    virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
    void CalculateInverseCovariance();
};

Linear Algebra Operations

Matrix

Basic matrix operations.

template<typename T, unsigned int NRows, unsigned int NColumns>  
class Matrix : public FixedArray<T, NRows * NColumns>
{
public:
    typedef Matrix                            Self;
    typedef FixedArray<T, NRows * NColumns>  Superclass;
    
    // Constructors
    Matrix();
    Matrix(const T & value);
    Matrix(const T matrix[NRows][NColumns]);
    Matrix(const InternalMatrixType & matrix);
    
    // Element access
    T & operator()(unsigned int row, unsigned int col);
    const T & operator()(unsigned int row, unsigned int col) const;
    T * operator[](unsigned int i);
    const T * operator[](unsigned int i) const;
    
    // Matrix operations
    Self operator+(const Self & matrix) const;
    Self operator-(const Self & matrix) const;
    Self & operator+=(const Self & matrix);
    Self & operator-=(const Self & matrix);
    Self & operator*=(const T & value);
    Self & operator/=(const T & value);
    Self operator*(const T & value) const;
    Self operator/(const T & value) const;
    
    // Matrix multiplication
    template<unsigned int NColumns2>
    Matrix<T, NRows, NColumns2> operator*(const Matrix<T, NColumns, NColumns2> & matrix) const;
    
    // Vector multiplication
    Vector<T, NRows> operator*(const Vector<T, NColumns> & vector) const;
    
    // Matrix properties
    vnl_matrix<T> GetVnlMatrix() const;
    void SetVnlMatrix(const vnl_matrix<T> & matrix);
    
    // Matrix operations
    vnl_matrix<T> GetInverse() const;
    vnl_matrix<T> GetTranspose() const;
    T GetTrace() const;
    T GetDeterminant() const;
    
    // Utilities
    void SetIdentity();
    void Fill(const T & value);
    
    // Dimension information
    static unsigned int GetNumberOfRows() { return NRows; }
    static unsigned int GetNumberOfColumns() { return NColumns; }
};

SymmetricSecondRankTensor

Symmetric tensor representation.

template<typename TComponent, unsigned int NDimension>
class SymmetricSecondRankTensor : public FixedArray<TComponent, NDimension * (NDimension + 1) / 2>
{
public:
    typedef SymmetricSecondRankTensor          Self;
    typedef FixedArray<TComponent, NDimension * (NDimension + 1) / 2> Superclass;
    
    // Constructors
    SymmetricSecondRankTensor();
    SymmetricSecondRankTensor(const ComponentType & r);
    SymmetricSecondRankTensor(const ComponentArrayType & r);
    SymmetricSecondRankTensor(const InternalMatrixType & matrix);
    
    // Element access
    ComponentType & operator()(unsigned int row, unsigned int col);
    const ComponentType & operator()(unsigned int row, unsigned int col) const;
    void SetComponent(unsigned int row, unsigned int col, const ComponentType & value);
    ComponentType GetComponent(unsigned int row, unsigned int col) const;
    
    // Matrix conversion
    void SetVnlMatrix(const vnl_matrix<ComponentType> & matrix);
    vnl_matrix<ComponentType> GetVnlMatrix() const;
    
    // Tensor operations
    Self operator+(const Self & tensor) const;
    Self operator-(const Self & tensor) const;
    Self & operator+=(const Self & tensor);
    Self & operator-=(const Self & tensor);
    Self operator*(const RealValueType & scalar) const;
    Self operator/(const RealValueType & scalar) const;
    Self & operator*=(const RealValueType & scalar);
    Self & operator/=(const RealValueType & scalar);
    
    // Eigenvalues and eigenvectors
    void ComputeEigenValues(EigenValuesArrayType & eigenValues) const;
    void ComputeEigenAnalysis(EigenValuesArrayType & eigenValues, EigenVectorsMatrixType & eigenVectors) const;
    
    // Tensor invariants
    AccumulateType GetTrace() const;
    RealValueType GetNorm() const;
    RealValueType GetSquaredNorm() const;
    
    // Tensor properties
    void SetIdentity();
    
    // Dimension information
    static unsigned int GetNumberOfComponents() { return InternalDimension; }
    
protected:
    void PrintSelf(std::ostream & os, Indent indent) const;
};

Numerical Utilities

NumericTraits

Type traits for numerical computations.

template<typename T>
class NumericTraits
{
public:
    typedef T                                 ValueType;
    typedef T                                 PrintType;
    typedef T                                 AbsType;
    typedef double                            AccumulateType;
    typedef double                            RealType;
    typedef RealType                          ScalarRealType;
    typedef float                             FloatType;
    
    // Constants
    static const T Zero;
    static const T One;
    static const T NonpositiveMin();
    static const T min();
    static const T max();
    
    // Type information
    static T ZeroValue();
    static T OneValue();
    static unsigned int GetLength(const T &);
    static unsigned int GetLength();
    
    // Comparison operations
    static bool IsPositive(T val);
    static bool IsNonpositive(T val);
    static bool IsNegative(T val);
    static bool IsNonnegative(T val);
    
    // Arithmetic operations
    static T AbsValue(T x);
    static AccumulateType AccumulateSquare(T x);
    static AccumulateType Accumulate(T x);
    static T AssignToValue(const AccumulateType & v);
    
    // Special values
    static bool IsInfinite(T val);
    static bool IsFinite(T val);
    static bool IsNaN(T val);
    
    // Limits
    static T min(T);
    static T max(T);
    static T NonpositiveMin(T);
    static T epsilon();
    static T infinity();
    static T quiet_NaN();
    static T signaling_NaN();
};

Math

Mathematical utilities and constants.

namespace Math
{
    // Mathematical constants
    static ITK_CONSTEXPR_VAR double pi = 3.14159265358979323846;
    static ITK_CONSTEXPR_VAR double e = 2.71828182845904523536;
    static ITK_CONSTEXPR_VAR double log2e = 1.44269504088896340736;
    static ITK_CONSTEXPR_VAR double log10e = 0.43429448190325182765;
    static ITK_CONSTEXPR_VAR double ln2 = 0.69314718055994530942;
    static ITK_CONSTEXPR_VAR double ln10 = 2.30258509299404568402;
    static ITK_CONSTEXPR_VAR double pi_2 = 1.57079632679489661923;
    static ITK_CONSTEXPR_VAR double pi_4 = 0.78539816339744830962;
    static ITK_CONSTEXPR_VAR double one_over_pi = 0.31830988618379067154;
    static ITK_CONSTEXPR_VAR double one_over_sqrt2pi = 0.39894228040143267794;
    static ITK_CONSTEXPR_VAR double two_over_pi = 0.63661977236758134308;
    static ITK_CONSTEXPR_VAR double two_over_sqrtpi = 1.12837916709551257390;
    static ITK_CONSTEXPR_VAR double sqrt2 = 1.41421356237309504880;
    static ITK_CONSTEXPR_VAR double sqrt1_2 = 0.70710678118654752440;
    
    // Utility functions
    template<typename TReturn, typename TInput>
    inline TReturn Round(TInput x);
    
    template<typename TReturn, typename TInput>
    inline TReturn RoundHalfIntegerToEven(TInput x);
    
    template<typename TReturn, typename TInput>
    inline TReturn RoundHalfIntegerUp(TInput x);
    
    template<typename TReturn, typename TInput>
    inline TReturn Floor(TInput x);
    
    template<typename TReturn, typename TInput>
    inline TReturn Ceil(TInput x);
    
    template<typename T1, typename T2>
    inline bool FloatAlmostEqual(T1 x1, T2 x2, typename NumericTraits<T1>::RealType radiusOfTolerance = NumericTraits<T1>::epsilon());
    
    template<typename T>
    inline bool FloatDifferenceULP(T1 x1, T2 x2, unsigned int maxUlps = 4);
    
    // Trigonometric functions
    inline double DegreesToRadians(double degrees);
    inline double RadiansToDegrees(double radians);
}

Common Usage Patterns

Optimization Setup

// Define cost function (example: mean squares metric)
typedef itk::MeanSquaresImageToImageMetric<FixedImageType, MovingImageType> MetricType;
MetricType::Pointer metric = MetricType::New();

// Configure metric with images and transform
metric->SetFixedImage(fixedImage);
metric->SetMovingImage(movingImage);
metric->SetTransform(transform);
metric->SetInterpolator(interpolator);
metric->SetFixedImageRegion(fixedImage->GetBufferedRegion());
metric->Initialize();

// Create optimizer
typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
OptimizerType::Pointer optimizer = OptimizerType::New();

// Configure optimizer
optimizer->SetCostFunction(metric);
optimizer->SetMaximumStepLength(4.0);
optimizer->SetMinimumStepLength(0.01);
optimizer->SetRelaxationFactor(0.9);
optimizer->SetNumberOfIterations(200);

// Set initial parameters
OptimizerType::ParametersType initialParameters(transform->GetNumberOfParameters());
initialParameters.Fill(0.0);
optimizer->SetInitialPosition(initialParameters);

// Run optimization
try {
    optimizer->StartOptimization();
    
    OptimizerType::ParametersType finalParameters = optimizer->GetCurrentPosition();
    double finalValue = optimizer->GetValue();
    
    std::cout << "Final parameters: " << finalParameters << std::endl;
    std::cout << "Final value: " << finalValue << std::endl;
    
} catch (itk::ExceptionObject & error) {
    std::cerr << "Optimization failed: " << error << std::endl;
}

Statistical Analysis

// Create sample data
typedef itk::Vector<double, 2> MeasurementVectorType;
typedef itk::Statistics::ListSample<MeasurementVectorType> SampleType;
SampleType::Pointer sample = SampleType::New();

// Add measurement vectors
MeasurementVectorType measurement;
measurement[0] = 1.0; measurement[1] = 2.0;
sample->PushBack(measurement);

measurement[0] = 2.0; measurement[1] = 4.0;
sample->PushBack(measurement);

measurement[0] = 3.0; measurement[1] = 6.0;
sample->PushBack(measurement);

// Create histogram
typedef itk::Statistics::Histogram<double, itk::Statistics::DenseFrequencyContainer2> HistogramType;
HistogramType::Pointer histogram = HistogramType::New();

// Initialize histogram
HistogramType::SizeType size(2);
size[0] = 10; // 10 bins in first dimension
size[1] = 10; // 10 bins in second dimension

HistogramType::MeasurementVectorType lowerBound(2);
HistogramType::MeasurementVectorType upperBound(2);
lowerBound[0] = 0.0; lowerBound[1] = 0.0;
upperBound[0] = 10.0; upperBound[1] = 10.0;

histogram->Initialize(size, lowerBound, upperBound);

// Fill histogram from sample
for (SampleType::Iterator iter = sample->Begin(); iter != sample->End(); ++iter) {
    histogram->IncreaseFrequency(iter.GetMeasurementVector(), 1);
}

// Calculate statistics
double mean0 = histogram->GetMean(0);
double variance0 = histogram->GetVariance(0);
double quantile95_0 = histogram->Quantile(0, 0.95);

std::cout << "Mean (dimension 0): " << mean0 << std::endl;
std::cout << "Variance (dimension 0): " << variance0 << std::endl;
std::cout << "95th percentile (dimension 0): " << quantile95_0 << std::endl;

Type Definitions

// Common optimizer instantiations
typedef RegularStepGradientDescentOptimizer           RegularStepGDOptimizer;
typedef GradientDescentOptimizer                      GDOptimizer;
typedef LBFGSOptimizer                                LBFGSOptimizer;
typedef AmoebaOptimizer                               AmoebaOptimizer;

// Common statistical types
typedef Statistics::ListSample<Vector<double, 2>>     ListSample2D;
typedef Statistics::ListSample<Vector<double, 3>>     ListSample3D;
typedef Statistics::ListSample<Vector<float, 2>>      FloatListSample2D;
typedef Statistics::ListSample<Vector<float, 3>>      FloatListSample3D;

typedef Statistics::Histogram<double>                 Histogram1D;
typedef Statistics::Histogram<double, 2>              Histogram2D;
typedef Statistics::Histogram<double, 3>              Histogram3D;

typedef Statistics::GaussianMembershipFunction<Vector<double, 2>> GaussianMembership2D;
typedef Statistics::GaussianMembershipFunction<Vector<double, 3>> GaussianMembership3D;

// Matrix types
typedef Matrix<double, 2, 2>                          Matrix2x2;
typedef Matrix<double, 3, 3>                          Matrix3x3;
typedef Matrix<double, 4, 4>                          Matrix4x4;
typedef Matrix<float, 2, 2>                           FloatMatrix2x2;
typedef Matrix<float, 3, 3>                           FloatMatrix3x3;
typedef Matrix<float, 4, 4>                           FloatMatrix4x4;

// Tensor types
typedef SymmetricSecondRankTensor<double, 2>          Tensor2D;
typedef SymmetricSecondRankTensor<double, 3>          Tensor3D;
typedef SymmetricSecondRankTensor<float, 2>           FloatTensor2D;
typedef SymmetricSecondRankTensor<float, 3>           FloatTensor3D;

// Common measurement vector types
typedef Vector<double, 2>                             MeasurementVector2D;
typedef Vector<double, 3>                             MeasurementVector3D;
typedef Vector<float, 2>                              FloatMeasurementVector2D;
typedef Vector<float, 3>                              FloatMeasurementVector3D;

// Statistical identifiers
typedef unsigned long                                  InstanceIdentifier;
typedef unsigned long                                  AbsoluteFrequencyType;
typedef double                                         RelativeFrequencyType;
typedef double                                         TotalAbsoluteFrequencyType;
typedef double                                         TotalRelativeFrequencyType;

// Optimization types
typedef Array<double>                                  ParametersType;
typedef Array<double>                                  DerivativeType;
typedef Array<double>                                  ScalesType;
typedef double                                         MeasureType;

ITK's mathematical operations framework provides comprehensive support for optimization, statistics, and numerical analysis, enabling sophisticated quantitative analysis in medical imaging applications.

Install with Tessl CLI

npx tessl i tessl/cmake-itk

docs

core-data-structures.md

image-processing.md

index.md

io-operations.md

mathematical-operations.md

mesh-processing.md

registration.md

segmentation.md

spatial-objects.md

tile.json