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 x1\mathbf{x}_1, x2\mathbf{x}_2, and x3\mathbf{x}_3 in three images:

[x2]×(i=13x1iTi)[x3]×=0[\mathbf{x}_2]_\times \left( \sum_{i=1}^3 x_{1i} T_i \right) [\mathbf{x}_3]_\times = 0

Where:

  1. [x2]×[\mathbf{x}_2]_\times: Skew-symmetric matrix derived from the coordinates of x2\mathbf{x}_2 (view 2).
  2. [x3]×[\mathbf{x}_3]_\times: Skew-symmetric matrix derived from the coordinates of x3\mathbf{x}_3 (view 3).
  3. i=13x1iTi\sum_{i=1}^3 x_{1i} T_i: A linear combination of the slices T1,T2,T3T_1, T_2, T_3 of the trifocal tensor TT, weighted by the coordinates x11,x12,x13x_{11}, x_{12}, x_{13} of the point x1\mathbf{x}_1 in the first view.

Key Components

  1. Skew-Symmetric Matrix: The skew-symmetric matrix [x]×[\mathbf{x}]_\times for a point x=[x,y,w]\mathbf{x} = [x, y, w]^\top is:

    [x]×=[0wyw0xyx0][\mathbf{x}]_\times = \begin{bmatrix} 0 & -w & y \\ w & 0 & -x \\ -y & x & 0 \end{bmatrix}

    This matrix represents the cross product x×v\mathbf{x} \times \mathbf{v}, allowing us to express epipolar constraints in matrix form.

  2. Slices of Trifocal Tensor: TiT_i (i=1,2,3i = 1, 2, 3) are the 3×33 \times 3 slices of the 3×3×33 \times 3 \times 3 trifocal tensor TT. These slices encode the geometric relationships between the three views.

  3. Equation Interpretation:

    • i=13x1iTi\sum_{i=1}^3 x_{1i} T_i: Constructs a matrix representing the relationship between x2\mathbf{x}_2 and x3\mathbf{x}_3, parameterized by x1\mathbf{x}_1.
    • [x2]×[\mathbf{x}_2]_\times: Ensures that the projected point x3\mathbf{x}_3 lies on the epipolar line induced by x1\mathbf{x}_1 in the second image.
    • [x3]×[\mathbf{x}_3]_\times: Ensures that the projected point x2\mathbf{x}_2 lies on the epipolar line induced by x1\mathbf{x}_1 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

  1. 3D Geometry and Projection: Let a 3D point X\mathbf{X} project to three points x1\mathbf{x}_1, x2\mathbf{x}_2, and x3\mathbf{x}_3 in the three images with camera matrices P1,P2,P3P_1, P_2, P_3:

    x1=P1X,x2=P2X,x3=P3X.\mathbf{x}_1 = P_1 \mathbf{X}, \quad \mathbf{x}_2 = P_2 \mathbf{X}, \quad \mathbf{x}_3 = P_3 \mathbf{X}.
  2. Epipolar Constraints:

    • In two-view geometry, the epipolar constraint relates x1\mathbf{x}_1 and x2\mathbf{x}_2 using the fundamental matrix FF: x2Fx1=0\mathbf{x}_2^\top F \mathbf{x}_1 = 0.
    • For three views, the trifocal tensor generalizes this constraint to account for correspondences across three images.
  3. Trifocal Tensor: The trifocal tensor TT encodes the relationship between three views and allows us to write the trilinear relationship:

    x2(i=13x1iTi)x3=0.\mathbf{x}_2^\top \left( \sum_{i=1}^3 x_{1i} T_i \right) \mathbf{x}_3 = 0.

    Expanding this into matrix form using [x2]×[\mathbf{x}_2]_\times and [x3]×[\mathbf{x}_3]_\times 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 TT), 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])

T=np.array([T100,T101,T102,T110,T111,T112,T120,T121,T122,T200,T201,T202,T210,T211,T212,T220,T221,T222,T300,T301,T302,T310,T311,T312,T320,T321,T322])
such that A*T=0, 
we can solve it by SVD of A, to find T. where p1,p2,p3 are point correspondences.


# 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)))



*Very Important Note*
The estimated trifocal tensor above (Direct Linear Estimation), is not a valid trifocal tensor but just the initial estimate of it. To read more about valid trifocal tensor read the article "Valid Trifocal Tensor and its Estimation".

Attachments for Experiment:

Images, I1,I2,I3.

Comments

Popular posts from this blog

Projection Matrices from Trifocal Tensor