miop.optimize_epipolar_geometry

Classes

OptimizeEpipolarGeometry([verbose, ...])

Optimize epipolar geometry using local refinement methods.

class miop.optimize_epipolar_geometry.OptimizeEpipolarGeometry(verbose=False, costFunction='sampson', kappa=2.5, searchRange=200, robustMethod='MLESAC', stdFixed=1.0, stdEstimation='adaptive')[source]

Bases: DAGNode

Optimize epipolar geometry using local refinement methods.

This class performs iterative local optimization of fundamental matrices and inliers obtained from robust estimation schemes (e.g., RANSAC, LMedS, MSAC, MLESAC). Different cost functions (Sampson, symmetric epipolar) and robust methods are supported.

Parameters:
  • verbose (bool, optional) – If True, prints diagnostic information during optimization. Default is False.

  • costFunction ({'sampson', 'symEpi'}, optional) – Cost function to use for evaluating epipolar geometry. Default is ‘sampson’.

  • kappa (float, optional) – Scaling factor for computing inlier thresholds. Default is 2.5.

  • searchRange (int, optional) – Search range (in pixels) for disparity when evaluating guided matching. Default is 200.

  • robustMethod ({'LMedS', 'RANSAC', 'MSAC', 'MLESAC'}, optional) – Robust estimation method for local optimization. Default is ‘MLESAC’.

  • stdFixed (float, optional) – Fixed value of the standard deviation used when stdEstimation=’fixed’. Default is 1.0.

  • stdEstimation ({'adaptive', 'fixed'}, optional) – Method to estimate standard deviation. If ‘adaptive’, a robust estimate is computed per iteration; if ‘fixed’, uses stdFixed. Default is ‘adaptive’.

compute_standard_deviation(numMatches, leastMedian)[source]

Compute robust or fixed estimate of the standard deviation.

Parameters:
  • numMatches (int) – Number of matches.

  • leastMedian (float) – Least median of residuals.

Returns:

  • std (float) – Estimated or fixed standard deviation.

  • threshold (float) – Threshold computed as (kappa * std) ** 2.

eval(epipolarSets, matches)[source]

Perform iterative local optimization over inlier matches.

Parameters:
  • epipolarSets (list of dict) – List of dictionaries containing the fundamental matrix (‘F’) and corresponding inliers for each stereo pair, as estimated by a SAC scheme.

  • matches (list of dict) – List of dictionaries containing matched points for each stereo pair.

Returns:

Updated epipolarSets with optimized fundamental matrices and refined inliers.

Return type:

list of dict

geometric_distance(pts1, pts2, F, costFunction, score)[source]

Compute geometric distance between corresponding points under a fundamental matrix.

Parameters:
  • pts1 (ndarray of shape (n, 2) or (n, 3)) – Points from the first image.

  • pts2 (ndarray of shape (n, 2) or (n, 3)) – Points from the second image.

  • F (ndarray of shape (3, 3)) – Fundamental matrix.

  • costFunction ({'sampson', 'symEpi'}) – Cost function to compute residuals.

  • score ({'sum', 'single'}) – Whether to return the sum of distances or per-point distances.

Returns:

distance – Geometric distance(s) depending on score.

Return type:

float or ndarray

local_opt_affine(matches, epiSet)[source]

Perform iterative local optimization of the best set yielded by the SAC scheme.

Guided matching is performed using the updated epipolar geometry until convergence or a stopping criterion is reached.

Parameters:
  • matches (dict) – Dictionary containing the matches in the stereo pair.

  • epiSet (dict) – Dictionary containing the initial fundamental matrix (‘F’) and corresponding inliers from the SAC scheme.

Returns:

  • npts1i (list of ndarray) – List of inlier points from image 1 across iterations.

  • npts2i (list of ndarray) – List of inlier points from image 2 across iterations.

  • Fi (list of ndarray) – Fundamental matrices estimated across iterations.

  • i (int) – Number of iterations performed.

  • rho (list) – Cost values across iterations (definition depends on chosen method).

  • stdi (list of float) – Standard deviations of residuals at each iteration.

local_opt_lmeds(matches, epiSet)[source]

Local optimization using Least Median of Squares (LMedS).

Parameters:
  • matches (dict) – Dictionary containing the matches in the stereo pair.

  • epiSet (dict) – Dictionary containing the initial fundamental matrix and inliers.

Returns:

  • npts1i (list of ndarray) – Inlier points in image 1 per iteration.

  • npts2i (list of ndarray) – Inlier points in image 2 per iteration.

  • Fi (list of ndarray) – Fundamental matrices estimated per iteration.

  • i (int) – Number of iterations performed.

  • mediani (list of float) – Median residuals across iterations.

  • stdi (list of float) – Standard deviations estimated per iteration.

local_opt_mlesac(matches, epiSet)[source]

Local optimization using MLESAC.

Parameters:
  • matches (dict) – Dictionary containing the matches in the stereo pair.

  • epiSet (dict) – Dictionary containing the initial fundamental matrix and inliers.

Returns:

  • npts1i (list of ndarray) – Inlier points in image 1 per iteration.

  • npts2i (list of ndarray) – Inlier points in image 2 per iteration.

  • Fi (list of ndarray) – Fundamental matrices estimated per iteration.

  • i (int) – Number of iterations performed.

  • rhoi (list of float) – Cost values computed per iteration.

  • stdi (list of float) – Standard deviations estimated per iteration.

local_opt_msac(matches, epiSet)[source]

Local optimization using MSAC.

Parameters:
  • matches (dict) – Dictionary containing the matches in the stereo pair.

  • epiSet (dict) – Dictionary containing the initial fundamental matrix and inliers.

Returns:

  • npts1i (list of ndarray) – Inlier points in image 1 per iteration.

  • npts2i (list of ndarray) – Inlier points in image 2 per iteration.

  • Fi (list of ndarray) – Fundamental matrices estimated per iteration.

  • i (int) – Number of iterations performed.

  • rhoi (list of float) – Cost values computed per iteration.

  • stdi (list of float) – Standard deviations estimated per iteration.

local_opt_ransac(matches, epiSet)[source]

Local optimization using RANSAC.

Parameters:
  • matches (dict) – Dictionary containing the matches in the stereo pair.

  • epiSet (dict) – Dictionary containing the initial fundamental matrix and inliers.

Returns:

  • npts1i (list of ndarray) – Inlier points in image 1 per iteration.

  • npts2i (list of ndarray) – Inlier points in image 2 per iteration.

  • Fi (list of ndarray) – Fundamental matrices estimated per iteration.

  • i (int) – Number of iterations performed.

  • lenPts (list of int) – Number of inliers across iterations.

  • stdi (list of float) – Standard deviations estimated per iteration.

max_expectation_gamma(std, errorArr, numMatches, vDist, iters=5)[source]

Compute the mixture parameter gamma via the expectation-maximization algorithm.

Parameters:
  • std (float) – Standard deviation of the residuals.

  • errorArr (ndarray) – Array of squared error values.

  • numMatches (int) – Number of matches.

  • vDist (float) – Parameter defined by the disparity search range.

  • iters (int, optional) – Number of EM iterations. Default is 5.

Returns:

gamma – Estimated mixture parameter.

Return type:

float

single_affine_fundamental_matrix(matches)[source]

Estimate an affine fundamental matrix using the affine gold standard algorithm.

Parameters:

matches (ndarray of shape (n, 4)) – Array of point correspondences with format (x1, y1, x2, y2).

Returns:

F – Estimated affine fundamental matrix.

Return type:

ndarray of shape (3, 3)