Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

undistortPoints

Correct point coordinates for lens distortion

Syntax

undistortedPoints = undistortPoints(points,cameraParams)
[undistortedPoints,reprojectionErrors] = undistortPoints(points,cameraParams)

Description

undistortedPoints = undistortPoints(points,cameraParams) returns point coordinates corrected for lens distortion. This function uses numeric nonlinear least-squares optimization.

example

[undistortedPoints,reprojectionErrors] = undistortPoints(points,cameraParams) additionally returns the errors used to evaluate the accuracy of undistorted points.

Examples

collapse all

Create an imageDatastore object containing calibration images.

images = imageDatastore(fullfile(toolboxdir('vision'),'visiondata', ...
   'calibration','mono'));
imageFileNames = images.Files;

Detect the calibration pattern.

[imagePoints,boardSize] = detectCheckerboardPoints(imageFileNames);

Generate world coordinates of the corners of the squares. The square size is in millimeters.

squareSize = 29; 
worldPoints = generateCheckerboardPoints(boardSize,squareSize);

Calibrate the camera.

I = readimage(images,10); 
imageSize = [size(I, 1), size(I, 2)];
params = estimateCameraParameters(imagePoints,worldPoints, ...
                                  'ImageSize',imageSize);

Load an image and detect the checkerboard points.

points = detectCheckerboardPoints(I);

Undistort the points

undistortedPoints = undistortPoints(points,params);

Undistort the image.

[J, newOrigin] = undistortImage(I,params,'OutputView','full');

Translate undistorted points

undistortedPoints = [undistortedPoints(:,1) - newOrigin(1), ...
                    undistortedPoints(:,2) - newOrigin(2)];

Display the results

figure; 
imshow(I); 
hold on;
plot(points(:,1),points(:,2),'r*-');
title('Detected Points'); 
hold off;

figure; 
imshow(J); 
hold on;
plot(undistortedPoints(:,1),undistortedPoints(:,2),'g*-');
title('Undistorted Points'); 
hold off;

Input Arguments

collapse all

Input points, specified as either a BRISKPoints, SURFPoints, MSERRegions, or cornerPoints object, or an M-by-2 matrix of M number of [x y] coordinates.

Camera parameters, specified as a cameraParameters or cameraIntrinsics object. You can return the cameraParameters object using the estimateCameraParameters function. The cameraParameters object contains the intrinsic, extrinsic, and lens distortion parameters of a camera.

Output Arguments

collapse all

Undistorted points, returned as an M-by-2 matrix. The undistortedPoints output contains M [x,y] point coordinates corrected for lens distortion. When you input points as double, the function outputs undistortedPoints as double. Otherwise, it outputs undistortedPoints as single.

Data Types: single | double

Reprojection errors, returned as an M-by-1 vector. You can use the errors to evaluate the accuracy of undistorted points. The function computes the errors by applying distortion to the undistorted points, and then taking the distances between the result and the corresponding input points. The reprojectionErrors output is in pixels.

Introduced in R2014b