The Trilinearity Equation For Trifocal Tensor Estimation (Direct Linear Estimation)
The trilinearity equation describes the geometric relationship between corresponding points in three views using the trifocal tensor. It encapsulates how points in the first two views can be used to predict the corresponding point in the third view.
The Trilinearity Equation
For three corresponding points , , and in three images:
Where:
- : Skew-symmetric matrix derived from the coordinates of (view 2).
- : Skew-symmetric matrix derived from the coordinates of (view 3).
- : A linear combination of the slices of the trifocal tensor , weighted by the coordinates of the point in the first view.
Key Components
-
Skew-Symmetric Matrix: The skew-symmetric matrix for a point is:
This matrix represents the cross product , allowing us to express epipolar constraints in matrix form.
-
Slices of Trifocal Tensor: () are the slices of the trifocal tensor . These slices encode the geometric relationships between the three views.
-
Equation Interpretation:
- : Constructs a matrix representing the relationship between and , parameterized by .
- : Ensures that the projected point lies on the epipolar line induced by in the second image.
- : Ensures that the projected point lies on the epipolar line induced by in the third image.
Geometric Meaning:
The equation ensures that the image correspondences satisfy the epipolar geometry induced by three views. In simpler terms, it guarantees that the projections of the same 3D point into the three views maintain geometric consistency.
Derivation of the Trilinearity Equation
-
3D Geometry and Projection: Let a 3D point project to three points , , and in the three images with camera matrices :
-
Epipolar Constraints:
- In two-view geometry, the epipolar constraint relates and using the fundamental matrix : .
- For three views, the trifocal tensor generalizes this constraint to account for correspondences across three images.
-
Trifocal Tensor: The trifocal tensor encodes the relationship between three views and allows us to write the trilinear relationship:
Expanding this into matrix form using and ensures that both left and right epipolar constraints are satisfied.
Simplified Form for Linear Estimation
The trilinearity equation expands into a system of 27 linear equations (one for each element of ), which can be solved using Singular Value Decomposition (SVD) for direct estimation of the trifocal tensor.
######## In a more simplified way we can write ########
A=np.array([p1[0]*p2[0]*p3[0],p1[0]*p2[0]*p3[1],p1[0]*p2[0],p1[0]*p2[1]*p3[0],p1[0]*p2[1]*p3[1],p1[0]*p2[1],p1[0]*p3[0],p1[0]*p3[1],p1[0],p1[1]*p2[0]*p3[0],p1[1]*p2[0]*p3[1],p1[1]*p2[0],p1[1]*p2[1]*p3[0],p1[1]*p2[1]*p3[1],p1[1]*p2[1],p1[1]*p3[0],p1[1]*p3[1],p1[1],p2[0]*p3[0],p2[0]*p3[1],p2[0],p2[1]*p3[0],p2[1]*p3[1],p2[1],p3[0],p3[1],1])
# Let me write the full python code to implement it
#%%
import numpy as np
p11=np.load('p1.npy')
p22=np.load('p2.npy')
p33=np.load('p3.npy')
def linearTrifocalTensor(p1,p2,p3):
A=[]
for p1,p2,p3 in zip(p11,p22,p33):
A.append(np.array([p1[0]*p2[0]*p3[0],p1[0]*p2[0]*p3[1],p1[0]*p2[0],p1[0]*p2[1]*p3[0],
p1[0]*p2[1]*p3[1],p1[0]*p2[1],p1[0]*p3[0],p1[0]*p3[1],p1[0],
p1[1]*p2[0]*p3[0],p1[1]*p2[0]*p3[1],p1[1]*p2[0],p1[1]*p2[1]*p3[0],p1[1]*p2[1]*p3[1],
p1[1]*p2[1],p1[1]*p3[0],p1[1]*p3[1],p1[1],p2[0]*p3[0],
p2[0]*p3[1],p2[0],p2[1]*p3[0],p2[1]*p3[1],p2[1],
p3[0],p3[1],1]))
_, _, V = np.linalg.svd(np.array(A))
t = V[-1, :]
T1=t[:9].reshape((3,3));T2=t[9:18].reshape((3,3));T3=t[18:].reshape((3,3));
T=np.dstack([T1,T2,T3])
return T
T=linearTrifocalTensor(p11, p22, p33)
#%%
def reprojection_error(T, p1, p2, p3):
"""
Compute the reprojection error for a trifocal tensor.
"""
error = []
for i in range(p1.shape[0]):
x1, y1 = p1[i]
x2, y2 = p2[i]
x3, y3 = p3[i]
for j in range(3):
eq = np.array([x2, y2, 1]) @ T[:, :, j] @ np.array([x3, y3, 1])
error.append(eq * np.array([x1, y1, 1])[j])
return np.array(error).flatten()
print("validation error rms: ", np.sqrt(np.mean(reprojection_error(T, p11, p22, p33)**2)))
Comments
Post a Comment