Homework 3
Q1. (A1) F using 8 Point Algorithm
Image 1
Image 1

Method:

  1. Normalization of points: The input points pts1 and pts2 are divided by max(image.shape) to scale them for numerical stability.
  2. Building the matrix A: Each pair of points forms a row using the equation [x1' * x1, x1' * y1, x1', y1' * x1, y1' * y1, y1', x1, y1, 1], building the matrix A.
  3. Computing the Fundamental Matrix using SVD: SVD on A gives the fundamental matrix F from the last singular vector reshaped to 3x3.
  4. Applying normalization transformation: F is refined using F = TT @ F @ T to account for scaling.
  5. Finally: F is refined using T.T @ F @ T and scaled by F[2][2].
Q1. (A2) E using 8 Point Algorithm

E = K2.T @ F @ K1

E = E / E[2][2]

E for bench:

                            -0.41524274  -8.81748894  -2.15055808
                            -1.3803559    0.79067134  69.08265036
                            -3.58890876 -68.47438701   1.        
        

E for remote:

                             2.5298064   -0.67056178   7.33094837
                            -6.62032749  -3.02768466 -28.29861665
                            -14.50071092  26.41824781   1.        
        

Q1. (B) F using 7 Point Algorithm
Image 1
Image 1

Method:

  1. Normalization of points: Input points pts1 and pts2 are divided by M to ensure numerical stability.
  2. Building the matrix A: Each pair of points forms a row using the equation [x1' * x1, x1' * y1, x1', y1' * x1, y1' * y1, y1', x1, y1, 1], generating the matrix A.
  3. Extracting two fundamental matrices: The last two singular vectors from the SVD of A are reshaped to obtain two matrices, F1 and F2.
  4. Linear combination of F1 and F2: F = a * F1 + (1 - a) * F2 is constructed, and the determinant is expanded to form a cubic polynomial in a.
  5. Solving the cubic equation: The roots of the cubic polynomial are found, corresponding to valid solutions for F.
  6. Finally : For each solution, F is refined using T.T @ F @ T and scaled by F[2][2].

Q2. RANSAC

Epipolar lines for 7 point algorithm

Image 1

Epipolar lines for 8 point algorithm

Image 1

Inliers vs Iterations plot

Image 1

Method:

  1. Randomly select 7 or 8 correspondences: For each iteration, a subset of point correspondences is randomly chosen from the input sets pts1 and pts2.
  2. Fit the Fundamental Matrix (F) using the 7-point or 8-point algorithm: Based on the selected correspondences, the algorithm computes an estimate of the fundamental matrix F using the specified method (7-point or 8-point).
  3. Compute epipolar lines and distances:For each point in pts1, calculate the epipolar line in the second image using F.T and find the distance from the corresponding point in pts2 to this line and vice-versa.
  4. Check for inliers: If the distance error for a point is below a specified threshold, the point is marked as an inlier. If the number of inliers in the current iteration exceeds the previous best, update the set of inliers.
  5. Compute the final Fundamental Matrix (F): Once the best set of inliers is identified, re-calculate F using only these inliers.
  6. Number of iterations: The algorithm runs for iterations = 2000 with a threshold_tol = 1.5.

Q3. Triangulation
Image 1 Image 1

Method:

  1. Build matrix A for each point: For each pair of corresponding points (a, b), the matrix A is constructed using the projection matrices P1 and P2 with the equation: A = [a_y * P1_3 - P1_2, P1_1 - a_x * P1_3, b_y * P2_3 - P2_2, P2_1 - b_x * P2_3].
  2. Compute 3D point: Apply SVD to A, and the last singular vector is the homogeneous coordinates of X. Scale X to make the last element = 1.
  3. Store the 3D points: The non-homogeneous part of X is extracted and stored in Points3D.

Q4. COLMAP
            #!/bin/bash
            IMAGE_DIR="hand"
            DATABASE_PATH="hand/database.db"
            SPARSE_MODEL_PATH="hand/sparse"

            colmap feature_extractor --database_path $DATABASE_PATH --image_path $IMAGE_DIR

            # Perform exhaustive feature matching
            colmap exhaustive_matcher --database_path $DATABASE_PATH

            mkdir -p $SPARSE_MODEL_PATH
            # Perform sparse reconstruction
            colmap mapper --database_path $DATABASE_PATH --image_path $IMAGE_DIR --output_path $SPARSE_MODEL_PATH
        
Image 1 Image 1 Image 1 Image 1

------------------------------------------------------------------------------------

Image 1 Image 1 Image 1 Image 1

Q5. Fundamental matrix estimation on your own images
Image 1
Image 1

Method:

  1. Find features in both images using SIFT and match them with FLANN-based matcher.
  2. Filter good matches and extract corresponding points.
  3. Estimate the fundamental matrix using RANSAC with the eight-point algorithm and visualize epipolar lines.