Skip to content

Distortion Models

RadialDistortion

Radial lens distortion model: r_d = r × (1 + k1·r² + k2·r⁴ + k3·r⁶).

Coordinates are in pixels relative to the optical center (image center). Supports pickle serialization.

Example::

d = tetra3rs.RadialDistortion(k1=-7e-9, k2=2e-15)
x_undistorted, y_undistorted = d.undistort(100.0, 200.0)

k1 property

First radial coefficient.

k2 property

Second radial coefficient.

k3 property

Third radial coefficient.

distort(x, y)

Forward distortion: ideal → distorted.

undistort(x, y)

Inverse distortion: distorted → ideal.

PolynomialDistortion

SIP-like polynomial distortion model with independent x,y correction terms.

Forward: x_d = x + Σ A_pq · (x/s)^p · (y/s)^q (0 ≤ p+q ≤ order) Inverse: x_i = x_d + Σ AP_pq · (x_d/s)^p · (y_d/s)^q

Where s = scale = image_width/2.

Includes all polynomial terms from order 0
  • (p+q = 0): constant offset — optical center shift
  • (p+q = 1): linear terms — residual scale & rotation
  • (p+q ≥ 2): higher-order distortion

Total coefficients per axis: (order+1)(order+2)/2.

Typically fitted from solve results via SolverDatabase.fit_polynomial_distortion(), or constructed directly from coefficient arrays (e.g. extracted from a FITS WCS SIP model). Supports pickle serialization.

order property

Polynomial order.

scale property

Normalization scale (typically image_width / 2).

num_coeffs property

Number of polynomial coefficients per axis.

a_coeffs property

Forward A coefficients (x correction, ideal → distorted).

b_coeffs property

Forward B coefficients (y correction, ideal → distorted).

ap_coeffs property

Inverse AP coefficients (x correction, distorted → ideal).

bp_coeffs property

Inverse BP coefficients (y correction, distorted → ideal).

__init__(order, scale, a_coeffs, b_coeffs, ap_coeffs, bp_coeffs)

Create a polynomial distortion model from coefficient arrays.

Each coefficient array must have exactly (order+1)(order+2)/2 elements, covering all terms from p+q=0 (constant offset) through p+q=order.

Parameters:

Name Type Description Default
order int

Polynomial order (2–6 typical).

required
scale float

Normalization scale (typically image_width / 2).

required
a_coeffs list[float]

Forward A coefficients (x correction, ideal → distorted).

required
b_coeffs list[float]

Forward B coefficients (y correction, ideal → distorted).

required
ap_coeffs list[float]

Inverse AP coefficients (x correction, distorted → ideal).

required
bp_coeffs list[float]

Inverse BP coefficients (y correction, distorted → ideal).

required

distort(x, y)

Forward distortion: ideal → distorted.

undistort(x, y)

Inverse distortion: distorted → ideal.

DistortionFitResult

Result of a distortion fitting procedure.

Returned by SolverDatabase.fit_radial_distortion or SolverDatabase.fit_polynomial_distortion.

model property

The fitted distortion model.

rmse_before_px property

RMS pixel residual before distortion correction.

rmse_after_px property

RMS pixel residual after distortion correction.

n_inliers property

Number of inlier matches in the final fit.

n_outliers property

Number of rejected outliers.

iterations property

Number of sigma-clip iterations performed.

inlier_mask property

Boolean inlier mask (True = inlier, False = outlier).