CS 6476: Project 3 / Camera Calibration and Fundamental Matrix Estimation with RANSAC

Overview

In this project, we use the geometric relationships between images taken from multiple views to compute camera positions and estimate fundamental matrices for various scenes.

Part I of the project required us to solve for the entries of the 3x4 camera projection matrix that maps 3D coordinates of objects present in a laboratory setting to 2D image points. After computing this camera projection matrix, we could determine the camera's center given these ground truth 3D-2D point correspondences.

Part II is estimating the mapping of points in one image to lines in another by means of the fundamental matrix. For this part of the project, I used Hartley's normalized eight-point algorithm to estimate a least-squares solution of the fundamental matrix parameters.

Part III leverages the VLFeat library to build SIFT feature descriptors around a number of interest points in both images in the stereo pair and takes the input SIFT descriptors to return matches based on the ratio test. In this part, we implement the RANSAC algorithm, which eliminates spurious correspondences found when matching using the ratio test, and combine this method with the normalized eight-point algorithm to estimate parameters for the fundamental matrix containing the greatest number of inliers. The criterion we use to distinguish inliers from outliers is based on a maximum absolute threshold from which an inlying pair of corresponding points (x, x') may not exceed according to the epipolar constraint equation

With RANSAC and the normalized eight-point algorithm, we are able to match corresponding points in both images with ~100% accuracy. Results for Part III are displayed for the Mount Rushmore, Notre Dame, Episcopal Gaudi, and Gaudi image pairs.

In addition, I found a separate image pair taken of the Angkor Wat temple (located in Cambodia) from two different viewing angles, ran the RANSAC algorithm to estimate the best fundamental matrix for these set of correspondences, and obtained reasonably accurate epipolar lines and point matches.

Part I: Camera Projection Matrix

The camera projection matrix

maps homogeneous 3D coordinates to 2D image coordinates as such

Since we are given 20 ground truth correspondences in pts2d-norm-pic_a.txt and pts3d-norm.txt, we can solve for M by setting up a homogeneous system of 40 equations (2 for each corresponding pair of 3D -> 2D points):

M has 12 elements, but since the scaling term is arbitrary, we only need to solve for 11 variables. Computing the least-squares solution to the system of equations, the projection matrix for the 20 normalized points in Picture A is

Writing M as the concatenation of a 3x3 matrix Q and a column matrix m4 as such

M = (Q | m_4 )

we can compute the camera center by solving

The total residual of this center estimate is 0.0445.

Likewise, the camera projection matrix and camera center for Picture B is

Part II: Fundamental Matrix Estimation

The normalized eight-point algorithm is used to compute the fundamental matrix given point correspondences x = (u, v) and x' = (u', v') in the left and right images, respectively. Each point correspondence generates one constraint on the fundamental matrix F and must satisfy the epipolar constraint equation

Expanding the matrices out by multiplication, we obtain the following equation for n point correspondences

where A is the n x 9 equation matrix, and f is a 9-element column vector containing the entries of the fundamental matrix F.

From here, the least-squares solution f is easily computed by performing singular value decomposition (SVD) on the matrix A=UDVT. It is well-known that the vector f that minimizes ||Af|| such that ||f|| = 1 can be found along the column of V corresponding to the least singular value. Next, we rearrange the 9 entries of f to create the 3x3 fundamental matrix F. Then, we perform SVD on F to obtain

We set the smallest singular value of Df to 0 to create matrix D'f, thus reducing the rank of the matrix from 3 to 2, and from there we can recompute the rank-2 fundamental matrix as

Using the version of the eight-point algorithm without prior coordinate normalization to compute the fundamental matrix on the laboratory image pair, we obtain the following fundamental matrix F (truncated to 4 decimal places) and the epipolar lines for both images:

If you look closely, you'll notice that the epipolar lines don't pass exactly through the center of all the point correspondences. How can we improve this?

However, in order to improve the accuracy of epipolar lines generated in Part III, we want to modify the 'vanilla' eight-point algorithm to recenter the point correspondences xi = (ui, vi) and x'i = (u'i, v'i) in both images to their respective centroids before proceeding to compute the least-squares solution for f. After recentering the image points, we must scale the points to be a fixed squared distance from the origin. The coordinate normalization steps can be summarized in the following steps:

  1. Compute the centroid of all corresponding points in a single image:
  2. Recenter by subtracting the mean u and v coordinates from the original point correspondences to obtain

  3. Define the scale term s and s' to be the average distances of the centered points from the origin in both the left and right images:

  4. Construct the transformation matrices Ta and Tb:

  5. The normalized correspondence points can be computed from

  6. Solve for the fundamental matrix F by applying the eight-point algorithm on the normalized set of point correspondences computed in the previous step.

  7. After obtaining the normalized fundamental matrix Fnorm, retrieve the fundamental matrix in the original coordinate frame using the following formula

    F_{orig} = T_{b}^{T} * F_{norm} * T_{a}

Using the normalized eight-point algorithm on the laboratory image pair, we get

and the fundamental matrix (truncated to 4 decimal places)

Part III: Fundamental Matrix with RANSAC

In practical situations, we will not be given ground truth correspondences between two images, so there must be a way to compute interest points and predict matches between stereo image pairs. We use the VLFeat library to generate SIFT descriptors around detected interest points and assign correspondences based on the nearest neighbor ratio test. In project 2, this method alone produced good results on some occasions, but on other image pairs (most notably the Episcopal Gaudi image set), it failed because there was no way to filter outliers from our results.

We now make use of RANSAC algorithm in tandem with the normalized eight-point algorithm to separate outliers. This addition allows us to estimate the best possible fundamental matrix with the greatest number of inliers.

RANSAC is an iterative algorithm that nondeterministically fits a model to a random sample of points taken from the dataset. As the number of permitted iterations increases, the more likely we are to find a fundamental matrix free of outliers. We can roughly estimate the number of iterations k needed to obtain a solution where some iteration of RANSAC selects only inliers with some probability p, using the following equation:

where w is the proportion of inliers in the data, and n is the number of points required to estimate the model.

So, for example, if we assume that 50% of the corresponding points returned in the SIFT description and matching phases are inliers, the expected number of iterations to run RANSAC in order to get a sample free of outliers with success probability 99% is equal to

For a pair of points in a stereo image to be considered a match, it must lie on the same epipolar line as well as satisfy the epipolar constraint. Programmatically, we define an absolute error threshold of .001 such that any pair (x, x') that satisfies the equation

is classified as an 'inlier' in the RANSAC algorithm.

Results

We display up to 35 random correspondences obtained after running RANSAC to compute the fundamental matrix.

Rushmore (unnormalized)

Ran 1000 iterations, error threshold = .001, no coordinate normalization. RANSAC returned 36/825 possible matches in 9.53 secs.


Notre Dame (normalized)

Ran 1000 iterations, error threshold = .001, with coordinate normalization. RANSAC returned 135/851 possible matches in 7.98 secs.


Woodruff (normalized)

Ran 2000 iterations, error threshold = .001, with coordinate normalization. RANSAC returned 52/887 possible matches in 21.94 secs.


Episcopal Gaudi (unnormalized)

Ran 10000 iterations, error threshold = .001, without coordinate normalization. RANSAC returned 76/1062 possible matches in 58.36 secs.


Episcopal Gaudi (normalized)

Ran 10000 iterations, error threshold = .001, with coordinate normalization. RANSAC returned 112/1062 possible matches in 59.06 secs.

Ahh... much better matching accuracy with coordinate normalization!


Angkor Wat (unnormalized)

Ran 1000 iterations, error threshold = .01, without coordinate normalization. RANSAC returned 25/456 possible matches in 9.51 secs.


Angkor Wat (normalized)

Ran 10000 iterations, error threshold = .001, with coordinate normalization. RANSAC returned 189/456 possible matches in 30.03 secs.