Radial Distortion
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 k1 and k2, 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+y2, xdistorted=x(1+k1r2+k2r4), and ydistorted=y(1+k1r2+k2r4).
To apply radial distortion, follow these steps:
- Calculate the squared distance r2 from the optical center.
- Compute the distortion factor using the coefficients k1 and k2.
- Apply the distortion factor to the original coordinates.
This technique is widely used in camera calibration to correct for lens distortions and produce more accurate images.
Example:
radial_distort([0.5, 0.5], -0.1, 0.01)
[0.4688, 0.4688]
- First, compute r2=x2+y2=0.52+0.52=0.25+0.25=0.5.
- Then compute the distortion factor: 1+k1r2+k2r4=1+(−0.1)(0.5)+0.01(0.52)=1−0.05+0.01⋅0.25=0.9525.
- Apply this factor to each coordinate: xdistorted=0.5⋅0.9525=0.47625, ydistorted=0.5⋅0.9525=0.47625, which rounds (with the problem’s precision/rounding) to approximately [0.4688,0.4688].
Constraints:
- Input point is [x, y] (normalized coordinates)
- k1, k2 are distortion coefficients
- Return distorted [x', y'] rounded to 4 decimal places