HW3: 3D reconstruction

python q1.py -a True

python q1.py -b True

python q2.py -p 7 -o hydrant

python q3.py

Q1: 8-point and 7-point algorithm (40 points)

(A1) F matrix using 8-point algorithm (15 points)

  1. Brief explanation of your implementation.

1. Data Preprocessing

Normalize the point coordinates to improve numerical stability. The normalization steps are as follows:

2. Construct Matrix A

In the normalized coordinate space, construct matrix A using each pair of matched points in the form:

    A = [x'1 x1   x'1 y1   x'1   y'1 x1   y'1 y1   y'1   x1   y1   1]

where (x1, y1) and (x'1, y'1) are the coordinates of corresponding points.

3. Solve for the Fundamental Matrix F

Perform Singular Value Decomposition (SVD) on matrix A and select the eigenvector corresponding to the smallest singular value (the null space of A) to reconstruct F:

4. Denormalization

The obtained F is in the normalized coordinate space, so it is transformed back to the original coordinate system as follows:

F = T2T F T1

where T1 and T2 are the respective normalization matrices.

5. Compute Epipolar Lines

Using the fundamental matrix F and points in one image, calculate the corresponding epipolar lines in the other image. The epipolar line satisfies:

l' = F ⋅ p

where p is a point in image 1, and l' is the epipolar line in image 2.

Name F-matrix visualizations
Bench
Bench
remote
remote

Fundamental Matrices

(A2) E matrix using 8-point algorithm (5 points)

  1. Brief explanation of your implementation.

Compute the Essential Matrix E

1. Calculate the Essential Matrix E

The essential matrix E is calculated using the fundamental matrix F and the intrinsic matrices K1 and K2 of the cameras. The formula is:

E = K2T ⋅ F ⋅ K1

where:

2. Normalization

To ensure consistency in the scale of the essential matrix, normalize E so that the last element of E equals 1:

E = E / E[2, 2]
  1. Provide your estimated E.

(B) 7-point algorithm (20 points)

  1. Brief explanation of your implementation.

1. Data Preprocessing

Normalize the point coordinates to improve numerical stability:

2. Construct Matrix A

In the normalized coordinate space, construct matrix A using each pair of matched points in the form:

    A = [x'1 x1   x'1 y1   x'1   y'1 x1   y'1 y1   y'1   x1   y1   1]

where (x1, y1) and (x'1, y'1) are the coordinates of corresponding points.

3. Solve for Candidate Fundamental Matrices F

Perform Singular Value Decomposition (SVD) to obtain the null space of matrix A:

4. Solve the Polynomial Equation

Solve the cubic polynomial to obtain possible real roots for α, with each real root providing a candidate fundamental matrix F.

5. Denormalization

Transform each candidate fundamental matrix from the normalized coordinate space back to the original coordinate system:

F = T2T F T1

where T1 and T2 are the normalization matrices.

Name F-matrix visualizations
hydrant
hydrant
ball
ball

Fundamental Matrices

Q2: RANSAC with 7-point and 8-point algorithm (20 points)

  1. Brief explanation of your RANSAC implementation and criteria for considering inliers.

1. Overview of the RANSAC Algorithm

RANSAC (Random Sample Consensus) is an iterative method used to find inliers and estimate model parameters from data that contains noise. For fundamental matrix estimation, the goal is to obtain a robust estimation of F by removing outliers.

2. Random Sampling and Model Fitting

In each iteration:

3. Error Calculation and Inlier Counting

For the calculated fundamental matrix F:

4. Dynamic Threshold and Early Stopping

To improve stability and efficiency, the threshold is reduced every 10% of the total iterations, tightening the inlier criteria.

If the inlier count remains stable for multiple rounds (up to early_stop_rounds), the iteration process terminates early.

5. Save the Best Fundamental Matrix F

The fundamental matrix F with the highest inlier count is returned as the best estimate.

Name Algorithm F-matrix visualizations
bench 8-Point
bench 8-Point
remote 8-Point
remote 8-Point
ball 8-Point
ball 8-Point
hydrant 8-Point
hydrant 8-Point
bench 7-Point
bench 7-Point
remote 7-Point
remote 7-Point
ball 7-Point
ball 7-Point
hydrant 7-Point
hydrant 7-Point

Fundamental Matrices

Name Algorithm % of inliers vs. # of RANSAC iterations
bench 8-Point
remote 8-Point
ball 8-Point
hydrant 8-Point
bench 7-Point
remote/td> 7-Point
ball 7-Point
hydrant 7-Point

Q3: Triangulation (20 points)

  1. Brief explanation of your implementation.

1. Skew-Symmetric Matrix Construction

Convert each 2D point in the image to a skew-symmetric matrix. Given a point x = (x, y, 1)T, the skew-symmetric matrix xskew is:

    xskew = 
    [  0  -1   y ]
    [  1   0  -x ]
    [ -y   x   0 ]

This matrix allows us to represent the cross product as a matrix multiplication, facilitating constraint construction.

2. Constraint Matrix Calculation

For each point correspondence, calculate constraint matrices using the skew-symmetric representation:

    Constraint1 = x1, skew ⋅ P1
    Constraint2 = x2, skew ⋅ P2

where P1 and P2 are the camera projection matrices, and x1 and x2 are the corresponding points in the two images. These constraint matrices will be used to solve for the 3D point.

3. Triangulating 3D Points

For each pair of constraints Constraint1 and Constraint2:

4. Color Extraction

For visualization, extract the color information for each 2D point from the first image. Each 2D point corresponds to a pixel in the image, and the RGB color values are stored for each 3D point.

5. Plotting the 3D Points

Finally, plot the 3D points using a scatter plot, where the coordinates (X, Y, Z) are colored according to the extracted pixel color information. This produces a colored 3D point cloud representing the scene.

  1. Results
Name Image
Point Cloud

Q4: Reconstruct your own scene! (20 points)

  1. DATASET SOURCE: https://www.agisoft.com/downloads/sample-data/
2D Correspondences reconstruction