PIXELBANKv8.2.1
Menu

Undistort Point

Implement a function to remove radial distortion from a given point in an image. This process is crucial in computer vision to correct for distortions introduced by camera lenses.

The concept of radial distortion arises when a camera's lens bends light rays, causing straight lines to appear curved. This distortion can be modeled using a polynomial expression, where the distorted coordinates xdx_d and ydy_d are related to the undistorted coordinates xx and yy through a distortion factor.

To correct for this distortion, we can use an iterative refinement process, such as Newton's method or fixed-point iteration, which refines an initial estimate of the undistorted coordinates until convergence. The steps involved are:

  1. Initialize the undistorted coordinates with the distorted coordinates
  2. Compute the distortion factor using the current estimate of the undistorted coordinates
  3. Update the estimate of the undistorted coordinates using the distortion factor
  4. Repeat steps 2-3 until convergence
r2=x2+y2r^2 = x^2 + y^2 \text{factor} = 1 + k_1r^2 + k_2r^2^2

This technique is widely used in image processing pipelines.

Example:

Input:
undistort_point([0.4688, 0.4688], -0.1, 0.01)
Output:
[0.5, 0.5]
Reasoning:
  • Start with distorted point xd=[0.4688,0.4688]\mathbf{x}_d = [0.4688, 0.4688] and radial model r2=x2+y2r^2 = x^2 + y^2, xd=xu(1+k1r2+k2r4)x_d = x_u(1 + k_1 r^2 + k_2 r^4) (applied similarly to yy) with k1=0.1k_1=-0.1, k2=0.01k_2=0.01.

  • Assume the undistorted point lies on the same ray, so try xu=[0.5,0.5]\mathbf{x}_u = [0.5, 0.5] and compute r2=0.52+0.52=0.5r^2 = 0.5^2 + 0.5^2 = 0.5.

  • Compute the radial factor: 1+k1r2+k2r4=1+(0.1)0.5+0.010.52=10.05+0.0025=0.95251 + k_1 r^2 + k_2 r^4 = 1 + (-0.1)\cdot 0.5 + 0.01 \cdot 0.5^2 = 1 - 0.05 + 0.0025 = 0.9525, and then the distorted coordinate: 0.50.9525=0.476250.46880.5 \cdot 0.9525 = 0.47625 \approx 0.4688 (the small mismatch is corrected by iteration).

  • Using Newton’s method or fixed-point iteration, the algorithm refines this guess until the forward distortion of xu\mathbf{x}_u matches [0.4688,0.4688][0.4688, 0.4688], converging to the undistorted output xu=[0.5,0.5]\mathbf{x}_u = [0.5, 0.5].

Constraints:

  • Use 10 iterations of fixed-point iteration
  • Return undistorted [x, y] rounded to 4 decimal places
Editor

Test Results

0/0
Run code to see test results.