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.

rectifyStereoImages

Rectify a pair of stereo images

Syntax

[J1,J2] = rectifyStereoImages(I1,I2,stereoParams)
[J1,J2] = rectifyStereoImages(I1,I2,tform1,tform2)
[J1,J2] = rectifyStereoImages(___,interp)
[J1,J2] = rectifyStereoImages(___,Name,Value)

Description

example

[J1,J2] = rectifyStereoImages(I1,I2,stereoParams) returns undistorted and rectified versions of I1 and I2 input images using the stereo parameters stored in the stereoParams object.

Stereo image rectification projects images onto a common image plane in such a way that the corresponding points have the same row coordinates. This image projection makes the image appear as though the two cameras are parallel. Use the disparity function to compute a disparity map from the rectified images for 3-D scene reconstruction.

[J1,J2] = rectifyStereoImages(I1,I2,tform1,tform2) returns rectified versions of I1 and I2 input images by applying projective transformations tform1 and tform2. The projective transformations are returned by the estimateUncalibratedRectification function.

example

[J1,J2] = rectifyStereoImages(___,interp) additionally specifies the interpolation method to use for rectified images. You can specify the method as 'nearest', 'linear', or 'cubic'.

example

[J1,J2] = rectifyStereoImages(___,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Specify images containing a checkerboard for calibration.

imageDir = fullfile(toolboxdir('vision'),'visiondata', ...
    'calibration','stereo');
leftImages = imageDatastore(fullfile(imageDir,'left'));
rightImages = imageDatastore(fullfile(imageDir,'right'));

Detect the checkerboards.

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

Specify world coordinates of checkerboard keypoints.

squareSizeInMillimeters = 108;
worldPoints = generateCheckerboardPoints(boardSize,squareSizeInMillimeters);

Read in the images.

I1 = readimage(leftImages,1);
I2 = readimage(rightImages,1);
imageSize = [size(I1,1),size(I1,2)];

Calibrate the stereo camera system.

stereoParams = estimateCameraParameters(imagePoints,worldPoints, ...
                                        'ImageSize',imageSize);

Rectify the images using 'full' output view.

[J1_full,J2_full] = rectifyStereoImages(I1,I2,stereoParams, ...
  'OutputView','full');

Display the result for 'full' output view.

figure;
imshow(stereoAnaglyph(J1_full,J2_full));

Rectify the images using 'valid' output view. This is most suitable for computing disparity.

[J1_valid,J2_valid] = rectifyStereoImages(I1,I2,stereoParams, ...
  'OutputView','valid');

Display the result for 'valid' output view.

figure;
imshow(stereoAnaglyph(J1_valid,J2_valid));

Input Arguments

collapse all

Input image corresponding to camera 1, specified as an M-by-N-by-3 truecolor image or an M-by-N 2-D grayscale array. Input images I1 and I2 must also be real, finite, and nonsparse. The input images must be the same class.

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

Input image corresponding to camera 2, specified as an M-by-N-by-3 truecolor image or an M-by-N 2-D grayscale array. Input images I1 and I2 must be real, finite, and nonsparse. The input images must also be the same class.

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

Stereo camera system parameters, specified as a stereoParameters object.

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

Projective transformations for image 1, specified as a 3-by-3 matrix returned by the estimateUncalibratedRectification function or a projective2d object.

Projective transformations for image 2, specified as a 3-by-3 matrix returned by the estimateUncalibratedRectification function or a projective2d object.

Interpolation method, specified as the character vector 'linear', 'nearest', or 'cubic' character vector.

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: 'OutputView', 'valid' sets the 'OutputView' property to the character vector 'valid'.

collapse all

Size of rectified images, specified as the comma-separated pair consisting of 'OutputView' and the character vector 'full' or 'valid'. When you set this parameter to 'full', the rectified images include all pixels from the original images. When you set this value to 'valid', the output images are cropped to the size of the largest common rectangle containing valid pixels.

When there is no overlap between rectified images, set the OutputView to 'full'.

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

Output Arguments

collapse all

Undistorted and rectified version of I1, returned as an M-by-N-by-3 truecolor image or as an M-by-N 2-D grayscale image.

Stereo image rectification projects images onto a common image plane in such a way that the corresponding points have the same row coordinates. This image projection makes the image appear as though the two cameras are parallel. Use the disparity function to compute a disparity map from the rectified images for 3-D scene reconstruction.

Undistorted and rectified version of I2, returned as an M-by-N-by-3 truecolor image or as an M-by-N 2-D grayscale image.

Stereo image rectification projects images onto a common image plane in such a way that the corresponding points have the same row coordinates. This image projection makes the image appear as though the two cameras are parallel. Use the disparity function to compute a disparity map from the rectified images for 3-D scene reconstruction.

References

[1] G. Bradski and A. Kaehler, Learning OpenCV : Computer Vision with the OpenCV Library. Sebastopol, CA: O'Reilly, 2008.

Extended Capabilities

Introduced in R2014a

Was this topic helpful?