Essential Matrix Estimation
Implement a method to estimate the essential matrix between two camera views using the 8-point algorithm. This task is crucial in image alignment and stitching as it relates corresponding points in two views through the equation p2TβEp1β=0. The essential matrix E encodes the rotation and translation between views, up to scale, and is a fundamental concept in computer vision.
To estimate E, the process involves several steps:
- Normalizing points to improve numerical stability
- Building a constraint matrix A from correspondences
- Solving Af=0 via Singular Value Decomposition (SVD)
- Enforcing a rank-2 constraint on E
This technique is widely used in structure from motion and stereo vision applications.
Example:
pts1 = [8 or more corresponding points] pts2 = [corresponding points in second view]
3Γ3 essential matrix
Each correspondence gives one constraint. 8 constraints β 8 equations for 9 unknowns in E. SVD finds the null space solution. Enforce rank-2 by zeroing smallest singular value.
Constraints:
- pts1, pts2: Corresponding normalized points (N, 2)
- Return: Essential matrix E (3Γ3) with rank 2
More from CV: Image Alignment and Stitching
- Background Knowledge
The essential matrix E encodes the relative pose (rotation R and translation t, up to scale) between two calibrated cameras. For a 3D point X seen in two views with normalized image coordinates p1β,\mathbf{p}2ββP2, the epipolar constraint is
p2TβEp1β=0.Geometrically, this says: the point in image 2 lies on the epipolar line obtained by transferring the point from image 1 via E.
Algebraically, E has special structure: it can be written as
E=[t]ΓβR,where [t]Γβ is the skew-symmetric matrix of translation t. This implies rank 2 and two equal non-zero singular values. The 8-point algorithm is a linear method: you stack linear constraints from at least 8 point correspondences into a matrix A, solve A\mathbf{f}=0 (where f is the vectorized E), then project the result onto the space of valid essential matrices (rank-2 constraint via SVD). Normalizing points (centering and scaling) is crucial for numerical stability.
- Algorithm/Approach
General pattern for essential (or fundamental) matrix estimation with the 8-point algorithm:
- Represent the epipolar constraint as a linear equation in the unknown entries of E.
- Use multiple point correspondences to build a linear system A\mathbf{f}=0.
- Solve for f as the right singular vector corresponding to the smallest singular value of A.
- Reshape f to a 3Γ3 matrix E, then enforce the rank-2 constraint via SVD.
- (In practice with RANSAC) repeat on random minimal subsets, score using inliers, and keep the best E.
- Step-by-Step Strategy
Assume you are given corresponding normalized image points {(x1β,y1β)}β{(x2β,y2β)} in homogeneous coordinates p1β=(x1β,y1β,1)T, p2β=(x2β,y2β,1)T.
a) Normalize points (Hartley-style normalization)
For each image separately:
- Compute centroid (xΛ,yΛβ).
- Compute average distance d of points to the centroid.
- Define scale s=\sqrt{2}/d.
- Build normalization transform
- Transform points: \tilde{\mathbf{p}} = T \mathbf{p} for both views, giving T1β,T2β.
b) Build matrix A
For each correspondence (\tilde{\mathbf{p}}_1, \tilde{\mathbf{p}}_2) with coordinates (x1β,y1β,1) and (x2β,y2β,1), the epipolar constraint expands to:
x2βx1βe11β+x2βy1βe12β+x2βe13β+y2βx1βe21β+y2βy1βe22β+y2βe23β+x1βe31β+y1βe32β+e33β=0.Create one row of A as:
[x2βx1β,Β x2βy1β,Β x2β,Β y2βx1β,Β y2βy1β,Β y2β,Β x1β,Β y1β,Β 1].- Stack all Nβ₯8 correspondences into an NΓ9 matrix A.
c) Solve A\mathbf{f}=0 via SVD
- Compute SVD of A: A=UΞ£VT.
- Take f as the last column of V (corresponding to smallest singular value).
- Reshape f into a 3Γ3 matrix E~.
d) Enforce rank-2 constraint on E
- Compute SVD of E~: E~=UEβΞ£EβVETβ, with Ξ£Eβ=\text{diag}(s1β,s2β,s3β).
- For an essential matrix, we need rank(E)=2 and two equal non-zero singular values; a simple enforcement is:
- Set s3β²β=0.
- Optionally set s1β²β=s2β²β=(s1β+s2β)/2.
- Form
e) Denormalize
Because you estimated E~ on normalized points:
E=T2TβEβ²T1β.You now have the essential matrix E relating original (calibrated) image coordinates.
- Common Pitfalls
- Skipping normalization: Leads to very poor numerical stability, especially when coordinates are large (pixel units) or unevenly distributed.
- Using uncalibrated coordinates: The essential matrix assumes points are in normalized camera coordinates (after multiplying pixel coords by Kβ1); otherwise you are really estimating the fundamental matrix instead.
- Too few or degenerate points:
- Need at least 8 non-degenerate correspondences (not all on a plane/line).
- Planar scenes or nearly collinear points can produce unstable or incorrect E.
- Incorrect SVD usage:
- Solving A\mathbf{f}=0: must take the right singular vector corresponding to the smallest singular value.
- Enforcing rank-2: must zero exactly one singular value, not more or less.
- Scale ambiguity: E is defined up to a non-zero scalar; donβt rely on its absolute scale. Any downstream pose decomposition should assume this.
- In RANSAC:
- Use a geometric error (e.g., symmetric epipolar distance) to score inliers.
- Ensure you re-estimate E using all inliers after RANSAC picks the best model.
- Time & Space Complexity
Let N be the number of correspondences.
-
Building A:
-
Time: O(N).
-
Space: O(N) for the NΓ9 matrix.
-
SVD of A:
-
Since width is constant (9), SVD is O(N) time in practice, with small constant factors.
-
Space: O(N) to store A plus O(1) for 9Γ9 matrices in the reduced SVD.
-
SVD of E (3Γ3):
-
Time: O(1).
-
Space: O(1).
Overall, time complexity is linear in the number of correspondences, O(N), and space complexity is O(N), dominated by storing A and the input matches. In RANSAC, you multiply this by the number of iterations, but each iteration still works on constant-sized subsets for the hypothesis step.