Geometry-based Methods for Vision
Assignment 3
Aviral Agrawal (avirala)
Q1 (A1) F matrix using 8-point algorithm
The algorithm for the 8-point algorithm is as follows:- Normalize the points in both images for stability purposes while estimating the fundamental matrix. Let the normalization matrix be \(T\). The normalization can be defined by the following equation: \(x_{norm} = T x\)
- Construct the system of linear equations based on the equation \(x_2^T F x_1 = 0\).
- This gives you a system of linear equations of the form \(Af = 0\), where \(f\) is the vectorized form of the fundamental matrix.
- Construct the matrix A by stacking the equations for all (eight) the point correspondences.
- Extract the fundamental matrix from the last row of \(V^T\)
- Enforce the rank-2 constraint on the fundamental matrix by setting the smallest singular value to zero.
- Denormalize the obtained fundamental matrix using the following equation: \(F = T^T F T\)
- Get the epipolar lines by the following equation: \(l_2 = F x_1\)
- Compute the Essential matrix using the following equation: \(E = K_2^T F K_1\), where \(K_1\) and \(K_2\) are the camera calibration matrices of the two cameras.
- Enforce the rank-2 constraint on the Essential matrix by setting the smallest singular value to zero and making the other two singular values equal by taking the average of the two.
- Normalize the points in both images for stability purposes while estimating the fundamental matrix. Let the normalization matrix be \(T\). The normalization can be defined by the following equation: \(x_{norm} = T x\)
- Construct the system of linear equations based on the equation \(x_2^T F x_1 = 0\).
- This gives you a system of linear equations of the form \(Af = 0\), where \(f\) is the vectorized form of the fundamental matrix.
- Construct the matrix A by stacking the equations for all (seven) the point correspondences.
- Extract the candidate fundamental matrices, \(F1_1\) and \(F1_2\), from the last row of \(V^T\)
- Now we construct the equation \(F = \alpha F1_1 + (1 - \alpha) F1_2\) and solve for \(\alpha\) by setting the \(det(F) = 0\)
- For the root obtained for the equation in the previous step, eliminate the imaginary roots and get the real root that minimizes the error. This gives the fundamental matrix.
- Enforce the rank-2 constraint on the fundamental matrix by setting the smallest singular value to zero.
- Denormalize the obtained fundamental matrix using the following equation: \(F = T^T F T\)
- Get the epipolar lines by the following equation: \(l_2 = F x_1\)
- Randomly select 8 points (or 7 points) from the set of correspondences.
- Estimate the Fundamental matrix using the selected points.
- Compute the error for each point by computing the epipolar line and the distance of the point from the epipolar line.
- Count the number of inliers by checking if the error is less than a threshold.
- Repeat the above steps for a fixed number of iterations and store the Fundamental matrix with the maximum number of inliers.
- We are given the camera matrices \(P_1\) and \(P_2\).
- Lets say that \(X\) is the 3D point we want to compute. Then, we use the equation \(x_1 = P_1 X\) and \(x_2 = P_2 X\) to get 4 constraints.
- Now, we solve the equation \(AX = 0\) where \(A\) matrix is formed by stacking the 4 constraints.
- Now, we solve the equation \(AX = 0\) using SVD and get the 3D point \(X\) using the last singular vector.
- Repeat the above steps for all the points and get the colored 3D point cloud.
- Extract the ORB features from the images to get the keypoints.
- Match the features using the Brute force matcher from CV2.
- Use the RANSAC algorithm to estimate the best Fundamental matrix using the 8-point algorithm.
- Display the epipolar lines and the points on the images like in the previous questions.
The Fundamental matrix computed from the 8-point algorithm for the Bench scene is: \[ F_{bench} = \begin{bmatrix} -1.19265833 \times 10^{-7} & -2.53255522 \times 10^{-6} & 2.07584109 \times 10^{-4} \\ -3.96465204 \times 10^{-7} & 2.27096267 \times 10^{-7} & 2.48867750 \times 10^{-2} \\ -1.06890748 \times 10^{-3} & -2.30052117 \times 10^{-2} & 1.00000000 \end{bmatrix} \]

The Fundamental matrix computed from the 8-point algorithm for the Remote scene is: \[ F_{remote} = \begin{bmatrix} 7.19006698 \times 10^{-7} & -1.90583125 \times 10^{-7} & 2.36215166 \times 10^{-3} \\ -1.88159055 \times 10^{-6} & -8.60510729 \times 10^{-7} & -8.45685523 \times 10^{-3} \\ -3.98058321 \times 10^{-3} & 9.46500248 \times 10^{-3} & 1.00000000 \end{bmatrix} \]

Q1 (A2). E matrix using 8-point algorithm
The algorithm for computing the Essentil matrix given the Fundamental matrix (using the eight point algorithm) is as follows:The Essential matrix computed from the 8-point algorithm for the Bench scene is: \[ E_{bench} = \begin{bmatrix} -0.18528359 & -3.93441194 & -0.95959081 \\ -0.61592238 & 0.35280189 & 30.82505761 \\ -1.60139078 & -30.55364717 & 0.44620549 \end{bmatrix} \]
The Essential matrix computed from the 8-point algorithm for the Remote scene is: \[ E_{remote} = \begin{bmatrix} 1.01667679 & -0.26948489 & 2.9461563 \\ -2.66057249 & -1.21676375 & -11.37262789 \\ -5.82753537 & 10.6169466 & 0.40187929 \end{bmatrix} \]
Q1 (B). 7-point algorithm
The algorithm for the 7-point algorithm is as follows for computing the Fundamental matrix is as follows:The Fundamental matrix computed from the 7-point algorithm for the Ball scene is: \[ F_{ball} = \begin{bmatrix} -3.35078059 \times 10^{-9} & -2.91545005 \times 10^{-6} & -6.74891733 \times 10^{-3} \\ 3.51682683 \times 10^{-6} & -8.84237457 \times 10^{-7} & -1.50044163 \times 10^{-2} \\ 9.09398538 \times 10^{-3} & 1.48748649 \times 10^{-2} & 1.00000000 \end{bmatrix} \]

The Fundamental matrix computed from the 7-point algorithm for the Hydrant scene is: \[ F_{hydrant} = \begin{bmatrix} 1.06836663 \times 10^{-7} & -3.30854241 \times 10^{-6} & -1.37397509 \times 10^{-3} \\ 4.79268901 \times 10^{-6} & 1.63305018 \times 10^{-7} & -1.67456794 \times 10^{-2} \\ 1.12974017 \times 10^{-3} & 1.64136613 \times 10^{-2} & 1.00000000 \end{bmatrix} \]

̊
Q2. RANSAC with 7-point and 8-point algorithm
The RANSAC algorithm is used to estimate the best Fundamental matrix using the 8-point (or 7-point) algorithms. The algorithm is as follows:NOTE: For the visualization of the results below, we show only 50 points and their corresponding epipolar lines.
Algorithm | Viewpoint 1 (points) and Viewpoint 2 (epipolar lines) | Estimated best F matrix |
---|---|---|
Ransac on Eightpoint algorithm | ![]() |
\( F_{bench} = \begin{bmatrix} -1.17732480 \times 10^{-8} & -5.96492484 \times 10^{-7} & -9.25459194 \times 10^{-5} \\ -2.11574661 \times 10^{-6} & 7.33247733 \times 10^{-7} & 2.38472741 \times 10^{-2} \\ -8.40950559 \times 10^{-4} & -2.23150919 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |
Ransac on Sevenpoint algorithm | ![]() |
\( F_{bench} = \begin{bmatrix} -6.00278924 \times 10^{-8} & -1.89901309 \times 10^{-6} & -1.01789158 \times 10^{-4} \\ -8.35050242 \times 10^{-7} & 6.35592554 \times 10^{-7} & 2.34660431 \times 10^{-2} \\ -7.75197644 \times 10^{-4} & -2.20073479 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |

Algorithm | Viewpoint 1 (points) and Viewpoint 2 (epipolar lines) | Estimated best F matrix |
---|---|---|
Ransac on Eightpoint algorithm | ![]() |
\( F_{remote} = \begin{bmatrix} 3.31549792 \times 10^{-7} & 1.83719791 \times 10^{-6} & 1.65131980 \times 10^{-3} \\ -4.99599151 \times 10^{-6} & -1.96519828 \times 10^{-6} & -1.09521744 \times 10^{-2} \\ -3.16482952 \times 10^{-3} & 1.34098309 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |
Ransac on Sevenpoint algorithm | ![]() |
\( F_{remote} = \begin{bmatrix} 9.07903785 \times 10^{-7} & 9.52425153 \times 10^{-6} & 2.80375262 \times 10^{-3} \\ -2.37640159 \times 10^{-5} & -1.12324145 \times 10^{-5} & -3.28032408 \times 10^{-2} \\ -5.52592264 \times 10^{-3} & 4.79981947 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |

Algorithm | Viewpoint 1 (points) and Viewpoint 2 (epipolar lines) | Estimated best F matrix |
---|---|---|
Ransac on Eightpoint algorithm | ![]() |
\( F_{ball} = \begin{bmatrix} 3.71042537 \times 10^{-7} & -2.25290945 \times 10^{-6} & -1.29575359 \times 10^{-2} \\ 2.83902820 \times 10^{-6} & -9.48009479 \times 10^{-7} & -2.08477087 \times 10^{-2} \\ 1.68824336 \times 10^{-2} & 2.03637835 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |
Ransac on Sevenpoint algorithm | ![]() |
\( F_{ball} = \begin{bmatrix} -1.12736128 \times 10^{-8} & -2.69063603 \times 10^{-6} & -5.47932562 \times 10^{-3} \\ 3.29220226 \times 10^{-6} & -7.78788925 \times 10^{-7} & -1.30644532 \times 10^{-2} \\ 7.31943242 \times 10^{-3} & 1.29175883 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |

Algorithm | Viewpoint 1 (points) and Viewpoint 2 (epipolar lines) | Estimated best F matrix |
---|---|---|
Ransac on Eightpoint algorithm | ![]() |
\( F_{hydrant} = \begin{bmatrix} 1.15137573 \times 10^{-7} & -3.55180795 \times 10^{-6} & -1.44531518 \times 10^{-3} \\ 5.07452803 \times 10^{-6} & 8.62427635 \times 10^{-8} & -1.69450956 \times 10^{-2} \\ 1.18864639 \times 10^{-3} & 1.66666913 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |
Ransac on Sevenpoint algorithm | ![]() |
\( F_{hydrant} = \begin{bmatrix} 8.03014968 \times 10^{-8} & -4.41774279 \times 10^{-6} & -1.17500281 \times 10^{-3} \\ 5.91955998 \times 10^{-6} & -6.29390198 \times 10^{-8} & -1.74127183 \times 10^{-2} \\ 9.10060610 \times 10^{-4} & 1.72900940 \times 10^{-2} & 1.00000000 \end{bmatrix} \) |

̊
Q3. Triangulation
The algorithm for triangulation is as follows:The colored point cloud formed by the given images:

̊
Q4. Reconstruct your own scene!
In this question, we use COLMAP to reconstruct the scene given multiview images of the scene. The reconstructed scene is shown below:
Multiview input images | Output |
---|---|
![]() |
![]() |
Multiview input images | Output |
---|---|
![]() |
![]() |
̊
Q5. Bonus 1 - Fundamental matrix estimation on your own images
The algorithm for computing the Fundamental matrix on own images is as follows:NOTE: For the visualization of the results below, we show only 10 points and their corresponding epipolar lines.
The Fundamental matrix computed from the 8-point algorithm for own scene 1 is: \[ F_{scene1} = \begin{bmatrix} 5.74826515 \times 10^{-7} & -1.26092227 \times 10^{-5} & 9.57701649 \times 10^{-3} \\ 1.36101425 \times 10^{-5} & -2.23535990 \times 10^{-7} & -6.07640109 \times 10^{-3} \\ -1.12669879 \times 10^{-2} & 5.34900814 \times 10^{-3} & 1.00000000 \end{bmatrix} \]
Image 1 | Image 2 |
---|---|
![]() |
![]() |

The Fundamental matrix computed from the 8-point algorithm for own scene 2 is: \[ F_{scene2} = \begin{bmatrix} -2.60929762 \times 10^{-7} & 3.72036573 \times 10^{-6} & -3.98388544 \times 10^{-3} \\ -3.32332766 \times 10^{-6} & -7.31945265 \times 10^{-9} & 3.97720202 \times 10^{-3} \\ 4.04310031 \times 10^{-3} & -5.04795628 \times 10^{-3} & 1.00000000 \end{bmatrix} \]
Image 1 | Image 2 |
---|---|
![]() |
![]() |

̊