Image undistortion is the process of correcting geometric distortions introduced by camera lenses, particularly radial and tangential distortions. These distortions cause straight lines to appear curved and alter spatial relationships within the image, especially near the edges. Such distortions can significantly impact the accuracy of measurements, 3D reconstruction, and other vision tasks that rely on precise spatial information.
Correcting these distortions is necessary for applications requiring precise spatial accuracy, including 3D reconstruction and image-based measurements.
Important Note: Undistortion is not a visual enhancement filter — it's a geometric correction for accurate spatial interpretation of image content.
When to Use Undistortion
Use image undistortion when:
- Your application requires accurate spatial measurements or alignment.
- You perform 3D reconstruction.
- Lens distortion impacts feature detection, tracking, or mapping.
Prerequisites
To undistort an image, you need the following:
- Intrinsic parameters: These define the internal characteristics of the camera, including focal length, principal point, and distortion coefficients. You can obtain these parameters by:
- Loading from a calibration file generated during a prior camera calibration, or
- Retrieving them directly from the camera, if supported by your hardware. For more information, see Up-/Downloading calibration parameters to/from a camera.
- Image metadata (optional): Metadata describes the conditions under which the image was captured (e.g., binning factors) that may differ from the calibration setup. Providing metadata ensures correct undistortion when capture conditions vary.
For instructions on performing camera calibration, refer to the Camera Calibration Guide.
Example
| Distorted Image | Undistorted Image |
| |
This example shows how a distorted input image is corrected using the undistortion process. Straight lines that appear curved due to lens distortion are restored to their true geometry.
Usage instructions
To apply undistortion, follow the steps below using one of the provided interfaces:
- C++
auto undistortedImage = undistortion.Process(image);
- C#
using var undistortion =
new Undistortion(calibrationParameters);
using var image = new Image("distorted_image.png");
using var undistortedImage = undistortion.Process(image);
- Python
calibration_parameters = CalibrationParameters.create_from_file("calibration_parameters.json")
undistortion = Undistortion(calibration_parameters)
image = Image.create_from_file("distorted_image.png")
undistorted_image = undistortion.process(image)
Load Calibration Data
Obtain one of the following, depending on your setup.
- CalibrationParameters: Load from a calibration file created during an earlier calibration process.
- IntrinsicParameters: May be obtained from a calibration file or queried directly from the camera (if the camera supports this).
- CalibrationResult: Use this if you're working directly with the output of a recent camera calibration session.
Initialize the Undistortion Object
Use one of the constructors to initialize Undistortion, optionally providing metadata if your image capture settings (e.g., binning) differ from the calibration images.
- Without metadata: Use this if your images were captured under the same conditions as the calibration images (same binning).
- With metadata: Provide metadata if your image capture settings differ from those used during calibration. This ensures internal parameters are properly adjusted and avoids delays due to internal reinitialization on the first call to the process function.
Process the Image
Call the process function on the initialized Undistortion instance, passing in the distorted image as an argument. The function will return an undistorted image with updated intrinsic parameters matching the undistorted image geometry.
The Undistortion instance internally precomputes and stores data structures that optimize the undistortion process and reduce runtime. For this reason, it is recommended to reuse the same instance for processing multiple images with the same calibration data, rather than creating a new instance each time.