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.

undistortImage

Correct image for lens distortion

Syntax

[J,newOrigin] = undistortImage(I,cameraParams)
[J,newOrigin] = undistortImage(I,cameraParams,interp)
[J,newOrigin] = undistortImage(___,Name,Value)

Description

example

[J,newOrigin] = undistortImage(I,cameraParams) returns an image, J, containing the input image, I, with lens distortion removed. The function also returns the [x,y] location of the output image origin. The location is set in terms of the input intrinsic coordinates specified in cameraParams.

[J,newOrigin] = undistortImage(I,cameraParams,interp) specifies the interpolation method for the function to use on the input image.

[J,newOrigin] = undistortImage(___,Name,Value) specifies one or more Name,Value pair arguments, using any of the preceding syntaxes. Unspecified properties have their default values.

Examples

collapse all

Create a set of calibration images.

images = imageDatastore(fullfile(toolboxdir('vision'),'visiondata', ...
    'calibration','fishEye'));

Detect calibration pattern.

[imagePoints,boardSize] = detectCheckerboardPoints(images.Files);

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

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

Calibrate the camera.

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

Remove lens distortion and display results.

I = images.readimage(1);
J1 = undistortImage(I,cameraParams);
figure; imshowpair(I,J1,'montage');
title('Original Image (left) vs. Corrected Image (right)');

J2 = undistortImage(I,cameraParams,'OutputView','full');
figure;
imshow(J2);
title('Full Output View');

Input Arguments

collapse all

Input image, specified in either M-by-N-by-3 truecolor or M-by-N 2-D grayscale. The input image must be real and nonsparse.

Data Types: single | double | int16 | uint8 | uint16 | logical

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

Interpolation method to use on the input image, specified as the character vector 'linear', 'nearest' , or 'cubic'.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'FillValues',0 sets the sets the output pixel fill values to 0.

collapse all

Output pixel fill values, specified as the comma-separated pair consisting of 'FillValues' and an array containing one or more fill values. When the corresponding inverse transformed location in the input image lies completely outside the input image boundaries, you use the fill values for output pixels. When you use a 2-D grayscale input image, you must set the FillValues to scalar. When you use a truecolor, FillValues can be a scalar or a 3-element vector of RGB values.

Size of output image, specified as the comma-separated pair consisting of 'OutputView' and the character vector 'same', 'full', or 'valid'. When you set the property to 'same', the function sets the output image to match the size of the input image. When you set the property to 'full', the output includes all pixels from the input image. When you set the property to 'valid', the function crops the output image to contain only valid pixels.

For the input image:

OutputViewOutput Image
'same'

Match the size of the input image.

'full'

All pixels from the input image.

'valid'

Only valid pixels from the input image.

Output Arguments

collapse all

Undistorted image, returned in either M-by-N-by-3 truecolor or M-by-N 2-D grayscale.

Data Types: single | double | int16 | uint8 | uint16 | logical

Output image origin, returned as a 2-element [x,y] vector. The function sets the output origin location in terms of the input intrinsic coordinates. When you set OutputView to 'same', which means the output image is the same size as the input image, the function sets the newOrigin to [0,0].

The newOrigin output represents the translation from the intrinsic coordinates of the output image J into the intrinsic coordinates of the input image I.

Let PI represent a point in the intrinsic coordinates of input image I.
Let PJ represent the same point in the intrinsic coordinates of the output image J.

PI = PJ + newOrigin

Extended Capabilities

Introduced in R2014a

Was this topic helpful?