v9.1.1
Menu

Radial Distortion

mediumFREELens DistortionsCamera ModelCV: Image Formation

Implement a function to apply radial distortion to normalized image coordinates, a crucial step in correcting lens distortions in computer vision. This process involves modeling the distortion that occurs when light passes through a camera lens, causing images to appear warped.

Radial distortion is a type of distortion that occurs when light rays bend differently as they pass through a lens, resulting in a distorted image. The distortion can be modeled using the distortion coefficients k1k_1 and k2k_2, which describe the amount of distortion present in the lens. The relationship between the original and distorted coordinates can be described using the equations r2=x2+y2r^2 = x^2 + y^2, xdistorted=x(1+k1r2+k2r4)x_{distorted} = x(1 + k_1 r^2 + k_2 r^4), and ydistorted=y(1+k1r2+k2r4)y_{distorted} = y(1 + k_1 r^2 + k_2 r^4).

To apply radial distortion, follow these steps:

  1. Calculate the squared distance r2r^2 from the optical center.
  2. Compute the distortion factor using the coefficients k1k_1 and k2k_2.
  3. Apply the distortion factor to the original coordinates.
r2=x2+y2r^2 = x^2 + y^2 xdistorted=x(1+k1r2+k2r4)x_{distorted} = x(1 + k_1 r^2 + k_2 r^4) ydistorted=y(1+k1r2+k2r4)y_{distorted} = y(1 + k_1 r^2 + k_2 r^4)

This technique is widely used in camera calibration to correct for lens distortions and produce more accurate images.

Example

Input
radial_distort([0.5, 0.5], -0.1, 0.01)
Output
[0.4762, 0.4762]
Reasoning
  • Inputs: point is a location (x,y)(x, y) in normalized image coordinates, measured from the optical center. k1 =−0.1= -0.1 and k2 =0.01= 0.01 set how much, and in which direction, points move radially: negative pulls inward (barrel), positive pushes outward (pincushion).
  • Radius: the squared distance from the center is r2=0.52+0.52=0.5r^2 = 0.5^2 + 0.5^2 = 0.5, which gives r4=0.25r^4 = 0.25.
  • Scale factor: 1+k1r2+k2r4=1−0.05+0.0025=0.95251 + k_1 r^2 + k_2 r^4 = 1 - 0.05 + 0.0025 = 0.9525. The negative k1k_1 term dominates, so the factor is below 1 and the point is pulled inward.
  • Output: both coordinates are multiplied by the same factor: 0.5×0.9525=0.476250.5 \times 0.9525 = 0.47625. Rounded to 4 decimal places that gives [0.4762, 0.4762]. 0.476250.47625 is a tie, but in floating point the product lands just below it, so it rounds to 0.47620.4762.
  • Notice: the direction from the center never changes, only the distance does. A point at the center (r=0r = 0) stays where it is, and with k1=k2=0k_1 = k_2 = 0 every point stays put.

Constraints

  • Input point is [x, y] (normalized coordinates)
  • k1, k2 are distortion coefficients
  • Return distorted [x', y'] rounded to 4 decimal places

Learn this in

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.