v9.1.1
Menu

Distortion Center Offset

mediumFREELens DistortionsCamera ModelCV: Image Formation

Implement a function to apply radial distortion with a distortion center offset. This task involves understanding how lens distortions affect image formation, particularly when the distortion center is not at the origin. The concept of radial distortion is crucial in computer vision as it helps correct for the nonlinear effects of camera lenses on image points, which can be described using the distortion center (cx,cy)(c_x, c_y) and distortion coefficients k1k_1 and k2k_2.

  1. Translate a point to the distortion center
  2. Apply radial distortion using the distortion coefficients
  3. Translate the distorted point back to its original position
r2=(x−cx)2+(y−cy)2r^2 = (x - c_x)^2 + (y - c_y)^2

The offset from the center is scaled by the radial factor 1+k1r2+k2r41 + k_1 r^2 + k_2 r^4:

xd=cx+(x−cx)(1+k1r2+k2r4),yd=cy+(y−cy)(1+k1r2+k2r4)x_d = c_x + (x - c_x)(1 + k_1 r^2 + k_2 r^4), \quad y_d = c_y + (y - c_y)(1 + k_1 r^2 + k_2 r^4)

This technique is widely used in image correction applications.

Example

Input
distort_with_center([1, 1], [0.5, 0.5], -0.1, 0)
Output
[0.975, 0.975]
Reasoning
  • Inputs: the point (x,y)=(1,1)(x, y) = (1, 1), the distortion center (cx,cy)=(0.5,0.5)(c_x, c_y) = (0.5, 0.5), and coefficients k1=−0.1k_1 = -0.1, k2=0k_2 = 0. Distortion is measured relative to the center, not the origin.
  • Relative to the center, the point sits at offset (0.5,0.5)(0.5, 0.5), so its squared radius is r2=0.52+0.52=0.5r^2 = 0.5^2 + 0.5^2 = 0.5 (and r4=0.25r^4 = 0.25).
  • The radial factor is 1+k1r2+k2r4=1+(−0.1)(0.5)+0⋅0.25=0.951 + k_1 r^2 + k_2 r^4 = 1 + (-0.1)(0.5) + 0 \cdot 0.25 = 0.95, so the offset shrinks to 0.95×0.5=0.4750.95 \times 0.5 = 0.475 in each coordinate.
  • Measured back from the center, the distorted point is 0.5+0.475=0.9750.5 + 0.475 = 0.975 in both xx and yy, giving [0.975, 0.975], rounded to 4 decimal places.
  • Notice that a negative k1k_1 pulls points toward the center (barrel distortion), and the pull grows with r2r^2. A point exactly at the center has r=0r = 0 and does not move: [0.5, 0.5] maps to [0.5, 0.5].

Constraints

  • center is [cx, cy]
  • Return distorted point 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.