Background Knowledge
Lens Distortion Fundamentals
Lens distortion occurs when light rays bend non-uniformly as they pass through a camera lens, causing straight lines in the world to appear curved in the captured image. Radial distortion is the most common type, where distortion increases with distance from the optical center. The relationship between undistorted coordinates (xu,yu) and distorted coordinates (xd,yd) is typically modeled as:
xd=xu(1+k1r2+k2r4+…)
yd=yu(1+k1r2+k2r4+…)
where r2=xu2+yu2 is the squared distance from the optical center, and k1,k2,… are radial distortion coefficients. The problem asks you to reverse this process: given distorted coordinates and distortion coefficients, recover the original undistorted coordinates.
Iterative Root-Finding Methods
This is fundamentally a nonlinear equation-solving problem. Newton's method and fixed-point iteration are two classical approaches for finding roots of nonlinear equations. Newton's method converges quadratically (very fast) near the solution but requires computing derivatives. Fixed-point iteration is simpler to implement but converges more slowly (linearly). Both methods work by repeatedly refining an initial guess until convergence.
Algorithm/Approach
The undistortion problem can be formulated as finding xu such that:
f(xu)=xu(1+k1r2+k2r4)−xd=0
where r2=xu2+yu2 depends on the unknown xu.
Newton's Method Approach:
xu,n+1=xu,n−f′(xu,n)f(xu,n)
This requires computing the derivative of the distortion model with respect to the undistorted coordinates.
Fixed-Point Iteration Approach:
Rearrange the equation into the form xu=g(xu) and iterate:
xu,n+1=g(xu,n)
For example, you might use xu,n+1=1+k1rn2+k2rn4xd where rn is computed from the previous iteration's estimate.
Step-by-Step Strategy
-
Initialize: Start with xu,0=xd and yu,0=yd (the distorted coordinates as initial guess, since distortion is typically small).
-
Compute Radius: Calculate r2=xu,n2+yu,n2 for the current estimate.
-
Apply Distortion Model: Compute the distortion factor factor=1+k1r2+k2r4+…
-
Update Estimate:
- For fixed-point: x_{u,n+1} = \frac{x_d}{\text{factor}}, y_{u,n+1} = \frac{y_d}{\text{factor}}
- For Newton: Compute the Jacobian and apply the Newton update formula
-
Check Convergence: Compare consecutive iterations. Stop when ∣xu,n+1−xu,n∣<ϵ and ∣yu,n+1−yu,n∣<ϵ for some small tolerance ϵ (e.g., 10−6).
-
Return Result: Return the converged undistorted coordinates.
Common Pitfalls
-
Poor Initial Guess: Starting far from the solution slows convergence. Using distorted coordinates as the initial guess is usually effective since distortion is typically small.
-
Insufficient Convergence Tolerance: Using too loose a tolerance may give inaccurate results. Use a small epsilon like 10−6 or 10−8.
-
Divergence: Fixed-point iteration can diverge if the iteration function's derivative has magnitude greater than 1 near the solution. Newton's method can also diverge if started far from the solution.
-
Numerical Instability: When computing r2 and high-order terms like r4, be careful with numerical precision, especially for large radii.
-
Iteration Limit: Always set a maximum iteration count to prevent infinite loops in case of non-convergence.
-
Handling Edge Cases: Points at or very near the optical center (where r≈0) may need special handling to avoid numerical issues.
Time & Space Complexity
Time Complexity: Each iteration requires O(1) operations (a few arithmetic operations). Fixed-point iteration typically requires O(n) iterations for n bits of precision, while Newton's method requires O(logn) iterations due to quadratic convergence. Overall: O(n) for fixed-point, O(logn) for Newton's method.
Space Complexity: O(1) — only a constant number of variables needed to store the current and previous estimates, distortion coefficients, and intermediate calculations.