Yang Parametric-Model Sub-Pixel Corner Fit | VitaVision
Back to atlas

Yang Parametric-Model Sub-Pixel Corner Fit

8 min readAdvancedView in graph
Based on
Sub-Pixel Chessboard Corner Localization for Camera Calibration and Pose Estimation
Yang, Zhao, Xian, Zhou · Applied Sciences 2018
DOI ↗

Goal

Refine pixel-level chessboard corner positions to sub-pixel accuracy by fitting a seven-parameter continuous model of an ideal chessboard corner directly to a raw image patch, without prior filtering. Input: a grayscale image I:Ω[0,255]I : \Omega \to [0, 255] and a set of pixel-level corner positions cp=[up,vp]Tc_p = [u_p, v_p]^T supplied by any coarse detector. Output: sub-pixel corner locations cs=cpdc_s = c_p - d where d=[μ,υ]Td = [\mu, \upsilon]^T is the displacement from the pixel-level estimate to the fitted corner centre, together with a per-corner fit-quality weight wm,n{0,1}w_{m,n} \in \{0, 1\} for use in downstream pose estimation. The model encodes Gaussian optical blur and a linear photometric transform, and the fit residual serves as a built-in quality metric for outlier rejection.

Algorithm

Let I:Ω[0,255]I : \Omega \to [0, 255] denote the grayscale image. Let (u,v)(u, v) denote coordinates within the (2r+1)×(2r+1)(2r+1) \times (2r+1) ROI centred on cpc_p, with r14r \approx 141515 px. Let μ,υ\mu, \upsilon denote the sub-pixel offset of the true corner from the pixel-level estimate, along uu and vv respectively. Let α\alpha denote the rotation angle of the first edge crossing the corner. Let β\beta denote the rotation-plus-shear angle of the second edge. Let λ\lambda denote the intensity gain mapping the binary model to the observed grayscale range. Let κ\kappa denote the intensity offset. Let σ\sigma denote the width of the Gaussian blur PSF. Let GσG_\sigma denote a 2-D isotropic Gaussian kernel with standard deviation σ\sigma. Let ρ\rho denote the approximation constant for the tanh\tanh-based surrogate of the Gaussian error function; ρ1.1\rho \approx 1.1 for 8-bit images.

Definition
Ideal corner model

A sign function along edge angle ϕ\phi through the shifted corner:

E(ϕ,u,v)=sgn((uμ)cosϕ+(vυ)sinϕ).E(\phi, u, v) = \operatorname{sgn}\bigl((u - \mu)\cos\phi + (v - \upsilon)\sin\phi\bigr).

The ideal corner model is the product of two such sign functions along edges at angles α\alpha (rotation) and β\beta (rotation plus shear):

Ci(u,v)=E(α,u,v)E(β,u,v),C_i(u, v) = E(\alpha, u, v) \cdot E(\beta, u, v),

which takes values ±1\pm 1 in the four quadrants of the ROI defined by the two crossing edges.

Definition
Blurred and scaled model

The blurred model is the convolution of the ideal model with the Gaussian PSF:

Cf(u,v)=(GσCi)(u,v).C_f(u, v) = (G_\sigma \ast C_i)(u, v).

The scaled model maps CfC_f to the observed intensity range via gain λ\lambda and offset κ\kappa:

Cs(u,v)=λCf(u,v)+κ.C_s(u, v) = \lambda \, C_f(u, v) + \kappa.
Definition
Closed-form surrogate

Introduce the composite angles

θ1=βα2,θ2=β+α2.\theta_1 = \frac{\beta - \alpha}{2}, \qquad \theta_2 = \frac{\beta + \alpha}{2}.

The Gaussian convolution integral is separated by integration by parts; the cross-term remainder Δ(u,v)\Delta(u, v) is estimated explicitly from θ1,θ2\theta_1, \theta_2 and added back. The Gaussian error function appearing in the separated integrals is replaced by

erf(x)tanh(ρx),ρ1.1,\operatorname{erf}(x) \approx \tanh(\rho\, x), \qquad \rho \approx 1.1,

yielding a tractable closed-form expression for CfC_f.

Definition
Nonlinear least-squares objective

Given observed intensity values Ii,jI_{i,j} at ROI pixels (ui,vj)(u_i, v_j), the residuals are

εi,j=Ii,jCs(ui,vj;  μ,υ,α,β,λ,κ,σ).\varepsilon_{i,j} = I_{i,j} - C_s(u_i, v_j;\; \mu, \upsilon, \alpha, \beta, \lambda, \kappa, \sigma).

The objective is the sum of squared residuals over the seven parameters:

minμ,υ,α,β,λ,κ,σ    i,jεi,j2.\min_{\mu,\upsilon,\alpha,\beta,\lambda,\kappa,\sigma} \;\; \sum_{i,j} \varepsilon_{i,j}^2.
Definition
Sub-pixel corner and self-check

The refined corner position is

cs=cpd,d=[μ,  υ]T.c_s = c_p - d, \qquad d = [\mu,\; \upsilon]^T.

Per-corner RMSE over the (2r+1)2(2r+1)^2 residuals:

E~m,n=1(2r+1)2i,jεi,j2.\tilde{E}_{m,n} = \sqrt{\frac{1}{(2r+1)^2} \sum_{i,j} \varepsilon_{i,j}^2}.

Across the full M×NM \times N board, compute quartiles Q1,Q3Q_1, Q_3 of {E~m,n}\{\tilde{E}_{m,n}\} and assign the reliability weight

wm,n={1E~m,n[2.5Q11.5Q3,  2.5Q31.5Q1],0otherwise.w_{m,n} = \begin{cases} 1 & \tilde{E}_{m,n} \in \bigl[2.5Q_1 - 1.5Q_3,\; 2.5Q_3 - 1.5Q_1\bigr], \\ 0 & \text{otherwise.} \end{cases}

The interval is the adjusted boxplot fence of Hubert and Vandervieren — wider than the standard 1.5IQR1.5 \cdot \mathrm{IQR} fence — to accommodate skewed residual distributions. The downstream PnP cost is weighted by wm,nw_{m,n}, so corners failing the self-check do not influence pose estimation.

Procedure

Algorithm
Yang sub-pixel corner fit
Input: Grayscale image II; pixel-level corner positions {cp(m,n)}\{c_p^{(m,n)}\} on an M×NM \times N board; ROI radius rr; initial edge angles α0,β0\alpha_0, \beta_0 from edge extraction.
Output: Sub-pixel corner positions {cs(m,n)}\{c_s^{(m,n)}\}; per-corner weights {wm,n}\{w_{m,n}\}.
  1. Extract the (2r+1)×(2r+1)(2r+1) \times (2r+1) ROI patch around each cpc_p.
  2. Initialise parameters: μ=υ=0\mu = \upsilon = 0, σ=1\sigma = 1; set α,β\alpha, \beta from the upstream edge-extraction result; set κ\kappa and λ\lambda from the mean gray levels of the local black and white patch regions.
  3. Evaluate Cs(u,v)C_s(u, v) using the closed-form tanh\tanh-based surrogate for CfC_f, with remainder Δ(u,v)\Delta(u, v) compensated via θ1,θ2\theta_1, \theta_2.
  4. Compute residuals εi,j=Ii,jCs(ui,vj)\varepsilon_{i,j} = I_{i,j} - C_s(u_i, v_j) over all ROI pixels.
  5. Form the Gauss–Newton normal system on the seven parameters and apply the update; repeat until convergence.
  6. Recover the refined corner: cs=cp[μ,υ]Tc_s = c_p - [\mu, \upsilon]^T.
  7. Compute E~m,n\tilde{E}_{m,n} for every corner on the board.
  8. Compute the adjusted boxplot interval from Q1,Q3Q_1, Q_3 of the board-level RMSE distribution and assign wm,nw_{m,n}.
  9. Pass (cs(m,n),wm,n)(c_s^{(m,n)}, w_{m,n}) to the downstream PnP or planar-calibration solver as weighted correspondences.

Implementation

The closed-form surrogate model evaluator and per-pixel residual — the inner kernel called by every Gauss–Newton iteration — in Rust:

/// Evaluate the scaled blurred-corner model C_s(u,v) at one pixel.
/// Inputs: ROI-centred coordinates (u, v), seven model parameters.
/// Returns the predicted intensity, using tanh(ρ·) as the erf surrogate.
fn model_intensity(
    u: f32, v: f32,
    mu: f32, nu: f32,
    alpha: f32, beta: f32,
    lambda: f32, kappa: f32, sigma: f32,
) -> f32 {
    const RHO: f32 = 1.1;
    let theta1 = 0.5 * (beta - alpha);
    let theta2 = 0.5 * (beta + alpha);
    let s = sigma * core::f32::consts::SQRT_2;
    let x1 = ((u - mu) * theta1.cos() + (v - nu) * theta1.sin()) / s;
    let x2 = ((u - mu) * theta2.cos() + (v - nu) * theta2.sin()) / s;
    let cf = (RHO * x1).tanh() * (RHO * x2).tanh();
    lambda * cf + kappa
}

/// Sum of squared residuals over the (2r+1)^2 ROI patch — the LSQ cost
/// minimised over (μ, υ, α, β, λ, κ, σ).
fn sse(roi: &[f32], r: usize, p: &[f32; 7]) -> f32 {
    let side = 2 * r + 1;
    let mut acc = 0.0;
    for row in 0..side {
        for col in 0..side {
            let u = col as f32 - r as f32;
            let v = row as f32 - r as f32;
            let pred = model_intensity(u, v, p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
            let res = roi[row * side + col] - pred;
            acc += res * res;
        }
    }
    acc
}

/// Per-corner RMSE feeding the boxplot self-check (Eq. 11).
fn corner_rmse(roi: &[f32], r: usize, p: &[f32; 7]) -> f32 {
    let n = ((2 * r + 1) * (2 * r + 1)) as f32;
    (sse(roi, r, p) / n).sqrt()
}

A standard Gauss–Newton or Levenberg–Marquardt loop wraps these primitives, using either an analytic Jacobian derived from model_intensity or finite differences. The fit's only paper-specific element is the surrogate evaluator above; the rest of the pipeline reuses generic LSQ machinery. The board-level boxplot weight wm,nw_{m,n} is computed once after all corners are fit by quantile estimation on {E~m,n}\{\tilde{E}_{m,n}\}.

Remarks

  • Per-corner cost is O((2r+1)2Niter)O((2r+1)^2 \cdot N_{\text{iter}}) for a fixed seven-parameter system; each Gauss–Newton step solves a 7×77 \times 7 normal system, independent of rr. Total cost scales linearly with the number of detected corners on the board.
  • ROI radius r14r \approx 141515 px is the practical sweet spot: smaller radii reduce the available fitting support; larger radii capture lens-distortion curvature that violates the locally-straight-edge assumption built into the model.
  • The tanh(ρx)\tanh(\rho x) approximation introduces a closed-form error that is small for ρ1.1\rho \approx 1.1 on 8-bit images; the explicit remainder Δ(u,v)\Delta(u, v) via θ1,θ2\theta_1, \theta_2 tightens the surrogate further. The constant ρ\rho requires re-tuning for inputs with dynamic range other than 8 bits.
  • The method operates on raw image patches without pre-filtering, eliminating the noise floor introduced by preprocessing steps such as cone or Gaussian filtering used by polynomial-saddle approaches.
  • The boxplot self-check uses the Hubert–Vandervieren adjusted fence, which is wider than the standard 1.5IQR1.5 \cdot \mathrm{IQR} fence; this accommodates skewed residual distributions arising under non-uniform illumination without rejecting valid corners unnecessarily.
  • The method is a refinement step, not a standalone detector: it requires pixel-level corner positions cpc_p from an upstream coarse detector and produces no result when cpc_p is missing or lies outside the ROI of the true corner.
  • Convergence assumes the upstream initialisation of α,β\alpha, \beta from edge extraction is accurate enough that the seven-parameter Gauss–Newton system is in the basin of the true minimum; quality of the angle initialisation directly affects the final fit.

References

  1. T. Yang, Q. Zhao, X. Wang, Q. Zhou. Sub-Pixel Chessboard Corner Localization for Camera Calibration and Pose Estimation. Applied Sciences, 8(11)
    , 2018. DOI: 10.3390/app8112118. PDF
  2. Z. Zhang. A Flexible New Technique for Camera Calibration. IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11)
    –1334, 2000. PDF
  3. V. Lepetit, F. Moreno-Noguer, P. Fua. EPnP: An Accurate O(n) Solution to the PnP Problem. International Journal of Computer Vision, 81(2)
    –166, 2009. PDF
  4. S. Placht, P. Fürsattel, E. A. Mengue, H. Hofmann, C. Schaller, M. Balda, E. Angelopoulou. ROCHADE: Robust Checkerboard Advanced Detection for Camera Calibration. ECCV, 2014.
  5. C. Harris, M. J. Stephens. A Combined Corner and Edge Detector. Alvey Vision Conference, 1988. PDF

Prerequisites

Compared with