Affine optimization
AffineOptimizer
- class valis.affine_optimizer.AffineOptimizer(nlevels=1, nbins=256, optimization='Powell', transformation='EuclideanTransform')[source]
Class that optimizes ridid registration
- optimization
Optimization method. Can be any method from scipy.optimize “FuzzyPSO” for Fuzzy Self-Tuning PSO in the fst-pso package (https://pypi.org/project/fst-pso/) “gp_minimize”, “forest_minimize”, “gbrt_minimize” from scikit-opt
- Type:
- accepts_xy
Bool declaring whether or not the optimizer will use corresponding points to optimize the registration
- Type:
- align(moving, fixed, mask, initial_M=None, moving_xy=None, fixed_xy=None)[source]
Align images by minimizing cost_fxn
Notes
All AffineOptimizer subclasses need to have the method align(moving, fixed, mask, initial_M, moving_xy, fixed_xy) that returns the aligned image, optimal_M, cost_list
AffineOptimizer subclasses must also have a cost_fxn(fixed_image, transformed, mask) method that returns the registration metric value
If one wants to use the same optimization methods, but a different cost function, then the subclass only needs to have a new cost_fxn method. See AffineOptimizerDisplacement for an example implementing a new cost function
Major overhauls are possible too. See AffineOptimizerMattesMI for an example on using SimpleITK’s optimization methods inside of an AffineOptimizer subclass
If the optimizer uses corressponding points, then the class attribute accepts_xy needs to be set to True. The default is False.
- __init__(nlevels=1, nbins=256, optimization='Powell', transformation='EuclideanTransform')[source]
AffineOptimizer registers moving and fixed images by minimizing a cost function
- Parameters:
nlevels (int) – Number of levels in the Gaussian pyramid
nbins (int) – Number of bins to have in histograms used to estimate mutual information
optimization (str) – Optimization method. Can be any method from scipy.optimize
transformation (str) – Type of transformation, “EuclideanTransform” or “SimilarityTransform”
- align(moving, fixed, mask, initial_M=None, moving_xy=None, fixed_xy=None)[source]
Align images by minimizing self.cost_fxn. Aligns each level of the Gaussian pyramid, and uses previous transform as the initial guess in the next round of optimization. Also uses other “good” estimates to define the parameter boundaries.
- Parameters:
moving (ndarray) – Image to warp to align with fixed
fixed (ndarray) – Image moving is warped to align with
mask (ndarray) – 2D array having non-zero pixel values, where values of 0 are ignnored during registration
initial_M ((3x3) array) – Initial transformation matrix
moving_xy (ndarray, optional) – (N, 2) array containing points in the moving image that correspond to those in the fixed image
fixed_xy (ndarray, optional) – (N, 2) array containing points in the fixed image that correspond to those in the moving image
- Returns:
aligned ((N,M) array) – Moving image warped to align with the fixed image
M ((3,3) array) – Optimal transformation matrix
cost_list (list) – list containing the minimized cost for each level in the pyramid
AffineOptimizerMattesMI
- class valis.affine_optimizer.AffineOptimizerMattesMI(nlevels=4.0, nbins=32, optimization='AdaptiveStochasticGradientDescent', transform='EuclideanTransform')[source]
Bases:
AffineOptimizer
Optimize rigid registration using Simple ITK
AffineOptimizerMattesMI is an AffineOptimizer subclass that uses simple ITK’s AdvancedMattesMutualInformation. If moving_xy and fixed_xy are also provided, then Mattes mutual information will be maximized, while the distance between moving_xy and fixed_xy will be minimized (the CorrespondingPointsEuclideanDistanceMetric in Simple ITK).
- Reg
sitk.ElastixImageFilter object that will perform the optimization
- Type:
sitk.ElastixImageFilter
- fixed_kp_fname
Name of file where to fixed_xy will be temporarily be written. Eventually deleted
- Type:
- moving_kp_fname
Name of file where to moving_xy will be temporarily be written. Eventually deleted
- Type:
- setup(moving, fixed, mask, initial_M=None, moving_xy=None, fixed_xy=None)[source]
Create parameter map and initialize Reg
- align(moving, fixed, mask, initial_M=None, moving_xy=None, fixed_xy=None)[source]
Align images by minimizing cost_fxn
- __init__(nlevels=4.0, nbins=32, optimization='AdaptiveStochasticGradientDescent', transform='EuclideanTransform')[source]
AffineOptimizer registers moving and fixed images by minimizing a cost function
- Parameters:
nlevels (int) – Number of levels in the Gaussian pyramid
nbins (int) – Number of bins to have in histograms used to estimate mutual information
optimization (str) – Optimization method. Can be any method from scipy.optimize
transformation (str) – Type of transformation, “EuclideanTransform” or “SimilarityTransform”
- align(moving, fixed, mask, initial_M=None, moving_xy=None, fixed_xy=None)[source]
Optimize rigid registration
- Parameters:
moving (ndarray) – Image to warp to align with fixed
fixed (ndarray) – Image moving is warped to align with
mask (ndarray) – 2D array having non-zero pixel values, where values of 0 are ignnored during registration
initial_M ((3x3) array) – Initial transformation matrix
moving_xy (ndarray, optional) – (N, 2) array containing points in the moving image that correspond to those in the fixed image
fixed_xy (ndarray, optional) – (N, 2) array containing points in the fixed image that correspond to those in the moving image
- Returns:
aligned ((N,M) array) – Moving image warped to align with the fixed image
M ((3,3) array) – Optimal transformation matrix
cost_list (None) – None is returned because costs are not recorded