Assignment 3: 3D reconstruction

16822: Geometry-Based Methods in Vision

Andrew id: shubhikg

Q1.(A1) F matrix using 8-point algorithm

Bench

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

The F matrix obtained is:

\[ F = \begin{bmatrix} -1.1926583293493763e-07 & -2.532555221255962e-06 & 0.0002075841088001709\\ -3.964652039267413e-07 & 2.2709626703632342e-07 & 0.024886775023525515\\ -0.001068907479083204 & -0.02300521171640414 & 1.0\\ \end{bmatrix} \]

Remote

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

The F matrix obtained is:

\[ F = \begin{bmatrix} 7.190066979504044e-07 & -1.9058312473919015e-07 & 0.0023621516586683224\\ -1.8815905465312522e-06 & -8.605107289862079e-07 & -0.008456855229034416\\ -0.0039805832062328 & 0.009465002483365294 & 1.0\\ \end{bmatrix} \]

Approach

F matrix is calculated using 8 points as follows:

1. Let x and x' be the corresponding points in both the images, then \( x'^TF x = 0\)

2. We will first normalize the points so that zero mean and unit variance. Let these matrixes be \(T_1\) and \(T2\).

3. Construct the matrix A using the following equation for each correspondence:

\[ A = \begin{bmatrix} x'_i x_i & x'_iy_i & x'_iy'_i & x_iy'_i & y_iy'_i & x_i & y_i & 1 \end{bmatrix} \]

4. Solve for f using SVD such taht Af = 0 and ||f|| = 1 and reshape the last singular vector of V to form F.

5. Enfore rank contraint for F by taking SVD of F and making the last singular value to be 0.

6. Unnormalzie F by \(F = T_2^T F T_1\)

7. Get epipolar lines using \(l' = Fx\)

Q1. (A2) E matrix using 8-point algorithm

Bench

\[ E = \begin{bmatrix} -0.41524274332836686 & -8.817489073498459 & -2.1505581339020683\\ -1.3803559343797978 & 0.790671373257647 & 69.08265198766989\\ -3.5889088130870825 & -68.47438807465731 & 1.0\\ \end{bmatrix} \]

Remote

\[ E = \begin{bmatrix} 2.529806511055498 & -0.6705617519726129 & 7.330948794711324\\ -6.620327883533977 & -3.0276848076485203 & -28.2986182875242\\ -14.500711069555596 & 26.418248077892116 & 1.0\\ \end{bmatrix} \]

Approach

E matrix is calculated using F matrix and intrinsics as follows:

1. Once we have obtained F using the above algorithm, then E is \( E = K_2^T F K_1\)

2. We can also enforce the last eigen value is 0 and the first eigen values are same by taking SVD and making the first 2 values as the mean of each other and making the last value 0.

Q1. (B) 7-point algorithm

Ball

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

The F and E matrices obtained are:

\[ F = \begin{bmatrix} -3.3507805937037184e-09 & -2.91545004523164e-06 & -0.006748917326873108\\ 3.5168268294336357e-06 & -8.842374574971407e-07 & -0.01500441630559245\\ 0.009093985381820229 & 0.014874864908709227 & 1.0\\ \end{bmatrix} \]
\[ E = \begin{bmatrix} -0.007879942236389693 & -6.856185520416274 & -11.375392044336904\\ 8.270427196633436 & -2.0794374247461502 & -16.72267004848027\\ 14.853385229504504 & 14.949060466979097 & 1.0\\ \end{bmatrix} \]

Hydrant

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

The F and E matrices obtained are:

\[ F = \begin{bmatrix} 1.0683666283784673e-07 & -3.3085424069649917e-06 & -0.0013739750860031687\\ 4.79268900746303e-06 & 1.6330501776660031e-07 & -0.016745679361476445\\ 0.001129740168884072 & 0.016413661258581885 & 1.0\\ \end{bmatrix} \]
\[ E = \begin{bmatrix} 0.14236495752587952 & -4.408790326699232 & -3.7364803960422677\\ 6.386486462140942 & 0.21761175039064723 & -16.40032880181337\\ 4.546725748896213 & 16.75194599026812 & 1.0\\ \end{bmatrix} \]

Approach

F matrix is calculated using 7 points as follows:

1. Let x and x' be the corresponding points in both the images, then \( x'^TF x = 0\)

2. We will first normalize the points so that zero mean and unit variance. Let these matrixes be \(T_1\) and \(T2\).

3. Construct the matrix A using the following equation for each of the 7 correspondences:

\[ A = \begin{bmatrix} x'_i x_i & x'_iy_i & x'_iy'_i & x_iy'_i & y_iy'_i & x_i & y_i & 1 \end{bmatrix} \]

4. Solve for f using SVD such that Af = 0 and ||f|| = 1.

5. Because we solved the SVD using 7 points, we will have the last 2 singular vectors of V representing 2 possible F i.e. \(F_1\) and \(F_2\).

6. F is a linear combination of \(F_1\) and \(F_2\) such that \(F = F_1 + \alpha F_2\) and det(F) = 0.

7. We obtain the value of \(\alpha\) by solving the cubic equation and then taking the real root value to form the correct F.

8. Enfore rank contraint for F by taking SVD of F and making the last singular eigen value to be 0.

9. Unnormalzie F by \(F = T_2^T F T_1\)

10. Get epipolar lines using \(l' = Fx\)

Q2. RANSAC with 7-point and 8-point algorithm

Bench

Eight Point: Viewpoint 1 (Points) Eight Point: Viewpoint 2 (Epipolar Lines) Seven Point: Viewpoint 1 (Points) Seven Point: Viewpoint 2 (Epipolar Lines)
Image 1 Image 2 Image 1 Image 2
Image 2

The F matrix obtained from 8 point RANSAC is:

\[ F_8 = \begin{bmatrix} -8.315919222036968e-08 & -1.8611756588189441e-06 & 0.0001242171040632345\\ -9.862919375002541e-07 & 3.968581466870647e-07 & 0.02470863952675043\\ -0.0010035156182164825 & -0.02294212119996662 & 1.0\\ \end{bmatrix} \]

The F matrix obtained from 7 point RANSAC is:

\[ F_7 = \begin{bmatrix} -7.314256510223699e-08 & -1.8746510657724156e-06 & 1.801163640585432e-05\\ -9.091639196622169e-07 & 4.4176193902177356e-07 & 0.024100671145184986\\ -0.0009060559790362064 & -0.022449752240386846 & 1.0\\ \end{bmatrix} \]

Remote

Eight Point: Viewpoint 1 (Points) Eight Point: Viewpoint 2 (Epipolar Lines) Seven Point: Viewpoint 1 (Points) Seven Point: Viewpoint 2 (Epipolar Lines)
Image 1 Image 2 Image 1 Image 2
Image 2

The F matrix obtained from 8 point RANSAC is:

\[ F_8 = \begin{bmatrix} 1.0628231982965163e-06 & -3.581886953854e-06 & 0.0029466657270109517\\ 2.129084507963991e-06 & 6.914700335412519e-07 & -0.007441439566800038\\ -0.004492700940921327 & 0.007208474246060887 & 1.0\\ \end{bmatrix} \]

The F matrix obtained from 7 point RANSAC is:

\[ F_7 = \begin{bmatrix} 1.850833218728248e-06 & -3.765911552912558e-06 & 0.0036379208574857666\\ -2.4694617002042795e-07 & -3.6599470725034026e-07 & -0.01044762615166601\\ -0.005362480924230808 & 0.011917125210599237 & 1.0\\ \end{bmatrix} \]

Ball

Eight Point: Viewpoint 1 (Points) Eight Point: Viewpoint 2 (Epipolar Lines) Seven Point: Viewpoint 1 (Points) Seven Point: Viewpoint 2 (Epipolar Lines)
Image 1 Image 2 Image 1 Image 2
Image 2

The F matrix obtained from 8 point RANSAC is:

\[ F_8 = \begin{bmatrix} -2.6317890668910927e-10 & -2.9972705378993896e-06 & -0.006841757326585823\\ 3.5891782123479925e-06 & -9.321532775411147e-07 & -0.0151574675209319\\ 0.009208643967401278 & 0.015080752357499139 & 1.0\\ \end{bmatrix} \]

The F matrix obtained from 7 point RANSAC is:

\[ F_7 = \begin{bmatrix} -8.932292313167013e-08 & -3.170734725565801e-06 & -0.006007652531533599\\ 3.7482797551257028e-06 & -9.290482463184898e-07 & -0.014485451649759909\\ 0.00823172223264148 & 0.014450646899784283 & 1.0\\ \end{bmatrix} \]

Hydrant

Eight Point: Viewpoint 1 (Points) Eight Point: Viewpoint 2 (Epipolar Lines) Seven Point: Viewpoint 1 (Points) Seven Point: Viewpoint 2 (Epipolar Lines)
Image 1 Image 2 Image 1 Image 2
Image 2

The F matrix obtained from 8 point RANSAC is:

\[ F_8 = \begin{bmatrix} 1.250799845236341e-07 & -3.933419581286565e-06 & -0.0013668343947613318\\ 5.4513856256308285e-06 & 5.0525799501333103e-08 & -0.01704536554346828\\ 0.0010120105194759163 & 0.016801810924058243 & 1.0\\ \end{bmatrix} \]

The F matrix obtained from 7 point RANSAC is:

\[ F_7 = \begin{bmatrix} 1.1033608466342571e-07 & -4.30253947069146e-06 & -0.0012436772715130999\\ 5.839291371027315e-06 & -2.3079284270849977e-08 & -0.017118304454976172\\ 0.0008950002424059402 & 0.01693784258647577 & 1.0\\ \end{bmatrix} \]

Approach

I followed the following steps to obtain the F using seven/eight point RANSAC algorithm:

1. In every iteration I select 7 or 8 points randomly for 7 and 8 point algorithm to estimate F.

2. I then calculate the inliers by computing the distance between the epipolar lines and the corresponding points in both images. All the points whose distance is less than a certain threshold are considered as inliers. For my experiment I took a threshold value of 3 pixels.

3. If the current number of inliers is greater than previous max, I update the inlier lest and best F.

4. This process is repeated for 10000 iterations.

5. In the end I use all the inliers using the max inlier number to re-estiamte the F matrix.

Q3. Triangulation

Visualisation

Image 1 Image 2

Approach

To do the triangulation, I did the following steps:

1. Let \(P_1\) and \(P_2\) be projection matrices for camera 1 and 2 and \(x_1\) and \(x_2\) be the corresponding 2 poin in both the images.

2. Then \(x_1 = P_1 X\) and \(x_2 = P_2 X\). So we have \(x_1 \times P_1 X = 0\) and \(x_2 \times P_2 X = 0\).Using these equations we can form A matrix as follows:

\[ A = \begin{bmatrix} P_1[0, :] - x_1[0]*P_1[2, :]\\ P_1[1, :] - x_1[1]*P_1[2, :]\\ P_2[0, :] - x_2[0]*P_2[2, :]\\ P_1[1, :] - x_1[1]*P_1[2, :]\\ \end{bmatrix} \]

3. We solve for X using SVD and take the last column of V as the answer.

4. This process is done for all point correspodences.

Q4. Reconstruct your own scene

Scene 1: India Gate

I collected multiple pictures of India Gate from the internet and used COLMAP on them.

Input

Image 1 Image 2 Image 2
Image 1 Image 2 Image 2

3D reconstruction

Image 2

Scene 2: Table

I collected multiple pictures of a table and used COLMAP on them.

Input

Image 1 Image 2 Image 2
Image 1 Image 2 Image 2

3D reconstruction

Image 2

5. Bonus 1 - Fundamental matrix estimation on your own images

Scene 1

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

Scene 2

Viewpoint 1 (Points) Viewpoint 2 (Epipolar Lines)
Image 1 Image 2

Approach

I did the following steps to obtain the F matrix on my own images:

1. Run SIFT to extract feature points and caluclate the descriptions for each feature point in both the images.

2. Do feature description matching of descriptors from both the images using FLANN matcher.

3. Eliminate noisy matches by retaining only those matches where the distance of the first nearest match is less than 0.75 times the distance of the second nearest match.

4. Use the matched keypoints from both the images to estimate F using RANSAC 7 or 8 point algorithm.

5. Plot the epipolar lines using the estimated F.