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 and , which describe the amount of distortion present in the lens. The relationship between the original and distorted coordinates can be described using the equations , , and .
To apply radial distortion, follow these steps:
- Calculate the squared distance from the optical center.
- Compute the distortion factor using the coefficients and .
- 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.4762, 0.4762]
- Inputs:
pointis a location in normalized image coordinates, measured from the optical center.k1andk2set 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 , which gives .
- Scale factor: . The negative term dominates, so the factor is below 1 and the point is pulled inward.
- Output: both coordinates are multiplied by the same factor: . Rounded to 4 decimal places that gives
[0.4762, 0.4762]. is a tie, but in floating point the product lands just below it, so it rounds to . - Notice: the direction from the center never changes, only the distance does. A point at the center () stays where it is, and with 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