Accelerating the pace of engineering and science

Documentation Center

• Trial Software

estimateUncalibratedRectification

Uncalibrated stereo rectification

Syntax

• [T1,T2] = estimateUncalibratedRectification(F,inlierPoints1,inlierPoints2,imagesize) example

Description

example

[T1,T2] = estimateUncalibratedRectification(F,inlierPoints1,inlierPoints2,imagesize) returns projective transformations for rectifying stereo images. This function does not require either intrinsic or extrinsic camera parameters. The input points can be M-by-2 matrices of M number of [x y] coordinates, or SURFPoints, MSERRegions, or cornerPoints object. F is a 3-by-3 fundamental matrix for the stereo images.

Examples

expand all

Rectify Stereo Images

Rectify stereo images using the projective transformation.

```I1 = imread('yellowstone_left.png');

Display point correspondences. Notice that the matching points are in different rows, indicating that the stereo pair is not rectified.

```showMatchedFeatures(I1, I2, inlier_points1, inlier_points2, 'montage');
title('Original images and inlier feature points');```

Compute the fundamental matrix from the corresponding points.

`f = estimateFundamentalMatrix(inlier_points1, inlier_points2, 'Method', 'Norm8Point');`

Compute the rectification transformations.

`[t1, t2] = estimateUncalibratedRectification(f, inlier_points1, inlier_points2, size(I2));`

Set the size and position of the rectified images.

```[w, h]   = deal(720, 620);  % Size of the rectified image
[x0, y0] = deal(-120, -30); % Upper-left corner of the rectified image
xLim = [0.5, w+0.5] + x0;
yLim = [0.5, h+0.5] + y0;
outputView = imref2d([h,w], xLim, yLim);```

Rectify the stereo images using projective transformations t1 and t2.

```I1Rect = imwarp(I1, projective2d(t1), 'OutputView', outputView);
I2Rect = imwarp(I2, projective2d(t2), 'OutputView', outputView);```

Transform the points to visualize them together with the rectified images.

```pts1Rect = transformPointsForward(projective2d(t1), inlier_points1);
pts2Rect = transformPointsForward(projective2d(t2), inlier_points2);```

Compensate for the shift in the coordinate system origin.

```pts1Rect = bsxfun(@minus, pts1Rect, [x0, y0]);
pts2Rect = bsxfun(@minus, pts2Rect, [x0, y0]);```

Notice that the inlier points now reside on the same rows. This also means that the epipolar lines are parallel to the x-axis.

```figure; showMatchedFeatures(I1Rect, I2Rect, pts1Rect, pts2Rect, 'montage');
title('Rectified images and the corresponding feature points');```

Input Arguments

expand all

F — Fundamental matrix for the stereo images 3-by-3 matrix

Fundamental matrix for the stereo images, specified as a 3-by-3 fundamental matrix. The fundamental matrix satisfies the following criteria:

 If P1, a point in image 1, corresponds to P2, a point in image 2, then: [P2,1] *F * [P1,1]' = 0

F must be double or single.

inlierPoints1 — Coordinates of corresponding pointsM-by-2 matrix | SURFPoints object | MSERRegions object | cornerPoints object

Coordinates of corresponding points in image one, specified as an M-by-2 matrix of M number of [x y] coordinates, or as a SURFPoints, MSERRegions, or cornerPoints object.

inlierPoints2 — Coordinates of corresponding pointsM-by-2 matrix | SURFPoints object | MSERRegions object | cornerPoints object

Coordinates of corresponding points in image one, specified as an M-by-2 matrix of M number of [x y] coordinates, or as a SURFPoints, MSERRegions, or cornerPoints object.

imagesize — Input image sizesingle | double | integer

Second input image size, specified as a double, single, or integer value and in the format returned by the size function. The size of input image 2 corresponds to inlierPoints2.

Output Arguments

expand all

T1 — Projective transformation one3-by-3 matrix

Projective transformation, returned as a 3-by-3 matrix describing the projective transformations for input image T1.

T2 — Projective transformation two3-by-3 matrix

Projective transformation, returned as a 3-by-3 matrix describing the projective transformations for input image T2.

expand all

Tips

• An epipole may be located in the first image or the second image. Applying the output uncalibrated rectification of T1 (or T2) to image 1 (or image 2) may result in an undesired distortion. You can check for an epipole within an image by applying the isEpipoleInImage function.

References

[1] Hartley, R. and A. Zisserman, "Multiple View Geometry in Computer Vision," Cambridge University Press, 2003.