dicoptimizer.hpp

struct OptResult

Public Functions

inline OptResult(size_t num_params)

Public Members

std::vector<double> p
double u = 0.0
double v = 0.0
double mag = 0.0
double ftol = 0.0
double xtol = 0.0
int iter = 0
double cost = 0.0
uint8_t converged = false
uint8_t above_thresh = false
class Optimizer

Public Functions

Optimizer(util::EShapeFunc shape_func, util::ECorrCrit cost_func, int max_iter, double precision, double threshold, int ss_size)
OptResult solve(const double cx, const double cy, subset::Pixels &ss_ref, subset::Pixels &ss_def, const Interpolator &interp_def, const bool check_on_thresh = false)
void set_rigid_displacement(double dx, double dy)
void copy_params_from_fft(const int idx, const std::vector<double> &shift_x, const std::vector<double> &shift_y)
void copy_params_from_neigh(const std::vector<double> &results_p, const int idx)
void copy_params_from_neigh(const std::vector<double> &results_p, const std::vector<double> &results_cost, const std::vector<uint8_t> &results_above_thresh, const std::vector<int> &neigh, const int fallback_idx)
int average_params_from_neigh(const std::vector<double> &results_p, const std::vector<uint8_t> &successful, const std::vector<int> &neigh)
void reset_params()

Public Members

const int num_params
int max_iter
std::vector<double> p
std::vector<double> dp
std::vector<double> pdp

Private Functions

void set_shape(util::EShapeFunc shape_func)
void set_cost_function(util::ECorrCrit corr_crit)

This function gets called before the corrolation optimization starts. Sets the function pointer for the user specified shape function.

Parameters:

corr_crit – [in] correlation criteria enum.

void debug_print(const int ss_x, const int ss_y, int iter, double costp, double ftol, double xtol)
Parameters:
  • ss_x –

  • ss_y –

void ssd(const subset::Pixels &ss_ref, subset::Pixels &ss_def, const Interpolator &interp_def, const double cx, const double cy)

calcutes the Sum of Squared Differences (SSD) between reference and deformed subsets.

Parameters:
  • ss_ref – [in] reference subset

  • ss_def – [inout] deformed subset

  • interp_def – [in] interpolator for deformed image

  • cx – [in] x coordinate at subset centre

  • cy – [in] y coordinate at subset centre

void nssd(const subset::Pixels &ss_ref, subset::Pixels &ss_def, const Interpolator &interp_def, const double cx, const double cy)

calcutes the Normalized Sum of Squared Differences (NSSD) between reference and deformed subsets.

Parameters:
  • ss_ref – [in] reference subset

  • ss_def – [inout] deformed subset

  • interp_def – [in] interpolator for deformed image

  • cx – [in] x coordinate at subset centre

  • cy – [in] y coordinate at subset centre

void znssd(const subset::Pixels &ss_ref, subset::Pixels &ss_def, const Interpolator &interp_def, const double cx, const double cy)

calcutes the Zero Normalized Sum of Squared Differences (ZNSSD) between reference and deformed subsets.

Parameters:
  • ss_ref – [in] reference subset

  • ss_def – [inout] deformed subset

  • interp_def – [in] interpolator for deformed image

  • cx – [in] x coordinate at subset centre

  • cy – [in] y coordinate at subset centre

bool invert_matrix(const std::vector<double> &matrix, std::vector<double> &inverse, std::vector<double> &augmented, int num_params)

Inverts square matrix using Gauss-Jordan elimination.

Parameters:
  • matrix – [in]

  • inverse – [out]

  • augmented – [in]

  • num_params – [in] Number of shape function parameters (2 for rigid, 6 for affine, …)

Returns:

true Matrix inversion was successful

Returns:

false Matrix inversion failed

void update_shapefunc_parameters(std::vector<double> &pdp, std::vector<double> &p, std::vector<double> &dp, std::vector<double> &invH, std::vector<double> &g, int num_params)

Updates the shape function parameters based on the current and updated parameters.

Parameters:
  • pdp – [out] shape function parameters for P+deltaP

  • p – [in] current shape function parameters P

  • dp – [out] the change in shape function for based on the Hessian and gradient

  • invH – [in] inverse of the Hessian matrix

  • g – [in] gradient vector

  • num_params – [in] Number of shape function parameters (2 for rigid, 6 for affine, …)

void update_lambda(double costp, double costpdp, std::vector<double> &p, std::vector<double> &pdp, double &lambda, int num_params)
Parameters:
  • costp – [in] cost value for current shape function parameters P

  • costpdp – [in] cost value for updated shape function parameters P+deltaP

  • p – [out] shape function parameters for P

  • pdp – [in] shape function parameters for P+deltaP

  • lambda – Optimization damping factor

  • num_params – [in] Number of shape function parameters (2 for rigid, 6 for affine, …)

void populate_hessian_lower_tri(std::vector<double> &H, double lambda, int num_params)

Populates the lower triangular part of the Hessian matrix, H.

Parameters:
  • H – [inout] Hessian matrix

  • lambda – [out] Optimization damping factor

  • num_params – [in] Number of shape function parameters (2 for rigid, 6 for affine, …)

Private Members

util::ECorrCrit criteria
double costp
double costpdp
std::vector<double> g
std::vector<double> dfdp
std::vector<double> dfdx
std::vector<double> dfdy
std::vector<double> H
std::vector<double> invH
std::vector<double> augmented
double lambda
const double precision
const double threshold
int px_vert
int px_hori
void (Optimizer::* optimize_cost)(const subset::Pixels&, subset::Pixels&, const Interpolator&, const double, const double)
void (*get_pixel)(double&, double&, const double, const double, const std::vector<double>&)
void (*get_dfdp)(std::vector<double>&, const double, const double, const double, const double)
void (*get_displacement)(double&, double&, const double, const double, const std::vector<double>&)

Private Static Functions

static int get_num_params(util::EShapeFunc shape_func)