HW1: Projective Geometry and Homography

Q1: Affine Rectification

1. Book 1

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9371821875600846 0.9998223351459001
0.9604739235699039 0.9984337670120885
Test lines on Input Image Test lines on Affine-Rectified Image

2. Catheral of Learning

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.8846805180330491 0.9992184827348348
-0.9889962539603023 -0.9999749666927263
Test lines on Input Image Test lines on Affine-Rectified Image

3. Chess

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9969648436407113 0.9999851164258383
0.9918753774962705 0.9993641037554953
Test lines on Input Image Test lines on Affine-Rectified Image

4. PNC Park (Baseball Park)

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9999309871379135 0.9999982299427344
-0.8429038628002343 -0.9999943805509471
Test lines on Input Image Test lines on Affine-Rectified Image

5. CMU Campus

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9294974463198948 0.999726913719186
0.9764751264710223 0.9998709829672254
Test lines on Input Image Test lines on Affine-Rectified Image

6. Checker

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9935148206038885 0.9999995645367928
-0.9555976463876774 -0.9999993838490685
Test lines on Input Image Test lines on Affine-Rectified Image

7. Tile_3

Input Image Annotated parallel lines on input image Affine-Rectified Image

Evaluate Angles

Before After
0.9958014969230224 0.9994924746220095
0.9939010749373381 -0.9999999494546261
Test lines on Input Image Test lines on Affine-Rectified Image

Brief description of the implementation

The affine rectification matrix is recovered from two pairs of parallel lines. The algorithm is as follows:

  1. Identify two sets of originally parallel lines in the image through annotation.
  2. For each set of parallel lines, recover the equations of the lines by computing the cross product of the corresponding points.
  3. For each pair of recovered lines, calculate their intersection point.
  4. Identify the intersection points for each pair of lines.
  5. Determine the line that passes through these intersection points, which corresponds to the imaged line at infinity.
  6. To find a transformation where \(l_{\infty} = \mathbf{H}^{-T}l_{\infty}{}'\), let \(l_{\infty} = [0, 0, 1]^T\) and \(l_{\infty}{}' = [l_1, l_2, l_3]^T\), the homography matrix is given by \(\mathbf{H} = \begin{bmatrix}1 & 0 & 0 \\ 0 & 1 & 0 \\ l_1 & l_2 & l_3 \end{bmatrix}\).

Q2: Metric Rectification

1. Apartment (Highland Ave.)

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
-0.3459156357953014 0.12531871660840646
0.1297324076302922 0.05377634980506488
Test lines on Input Image Test lines on Metric-Rectified Image

2. book1

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
-0.40586752869418447 0.0009465485567790611
0.44497613697420285 -0.08583273352765257
Test lines on Input Image Test lines on Metric-Rectified Image

3. cathedral of learning

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
0.34134104757860134 -0.023531255969838412
0.20654380999352198 0.001003814940055203
Test lines on Input Image Test lines on Metric-Rectified Image

4. Tile_5

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
-0.01812838027869386 0.08264760487022367
0.17122271592614757 -0.013508441825961524
Test lines on Input Image Test lines on Metric-Rectified Image

5. Tile_3

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
0.2747298649620067 -0.05089189418736821
0.5169986122212339 -0.005711570372005017
Test lines on Input Image Test lines on Metric-Rectified Image

6. CMU Campus

Input Image Annotated perpendicular lines on input image Annotated perpendicular lines on Affine-Rectified Image Rectified Image
Before After
0.37370722717095217 0.24998584769888313
0.5296647746859581 -0.06921147412182048
Test lines on Input Image Test lines on Metric-Rectified Image

Brief description of the implementation

The metric rectification matrix is recovered using two pairs of parallel lines and two pairs of perpendicular lines. The process involves first performing affine rectification based on q1.py, followed by metric rectification using affine-rectified lines. The algorithm proceeds as follows:

  1. Identify Orthogonal Lines: Annotate the image to identify two sets of originally orthogonal lines.
  2. Recover Line Equations: For each set of orthogonal lines, recover their equations by computing the cross product of the corresponding points. Denote the recovered lines as \(l'\) and \(m'\).
  3. Find Conic Dual to Circular Points: For each pair of lines, solve for the conic dual to the circular points using the relation: \(l'^T C^*_{\infty}{}' m' = 0\)
  4. Affine Rectified Conic: Since the image is already affine-rectified, the conic can be expressed as: \(C^*_{\infty} = \begin{bmatrix} a & \frac{b}{2} & 0 \\ \frac{b}{2} & c & 0 \\ 0 & 0 & 0 \end{bmatrix}\). The equation becomes \(A c = 0\), where \(c = [a, b, c]^T\). With two constraints from the two orthogonal pairs, the conic can be determined by Singular Value Decomposition. The solution is the null space of \(A\).
  5. Metric Rectification: Compute the SVD of the conic. Then, find the homography. \(C^*_{\infty} = H C^*_{\infty}{}' H^T\). The solution is: \(H = \begin{bmatrix} \sqrt{\sigma_1^{-1}} & 0 & 0 \\ 0 & \sqrt{\sigma_2^{-1}} & 0 \\ 0 & 0 & 1 \end{bmatrix} U^T\) Here, \(\sigma_1\) and \(sigma_2\) are the singular values from the SVD, and \(U\) is the orthogonal matrix obtained from the decomposition.

Q3: Planar Homography from Point Correspondences

Desk-Perspective

Normal Image Perspective Image Annotated corners in Perspective Image Warped and Overlaid Image

Wedding Album

Normal Image Perspective Image Annotated corners in Perspective Image Warped and Overlaid Image

Brief description of the implementation

  1. Recovering Homography: The homography matrix \(H\) is recovered from four sets of correspondences. Each correspondence generates two constraints of the form \(H\mathbf{x} \times \mathbf{x}' = 0\). These constraints can be written as: $ [0  -w’^T  y’^T] = 0$ and \([w'\mathbf{x}^T \ 0 \ -x'\mathbf{x}^T] \mathbf{h} = 0\) wher \(\mathbf{h}\) is a \(9 \times 1\) vectorized representation of the homography matrix.

  2. Solving for Homography: Given more than four correspondences (resulting in more than 8 constraints), the homography is solved using Singular Value Decomposition (SVD). The solution corresponds to the null space of the system of equations.

  3. Warping and Pasting: Once the homography is computed, the source image is warped and pasted onto the target plane based on the homography matrix. This process is implemented in the q3.py/warp_and_paste function.


Q4: Bonus: Metric Rectification from Perpendicular Lines

Concrete Floor Blocks

Input Image Annotated perpendicular lines Rectified Image
Before After
-0.564460052340408 -0.24018357406715019
0.17962590134696604 0.07974522228289
0.30334757235841797 -0.026637972024957646
Test lines on Input Image Test lines on Metric-Rectified Image

TownHouse

Input Image Annotated perpendicular lines Rectified Image
Before After
0.2272296156064184 -0.012039256130649403
0.1875139031883106 -0.23469204701506322
0.2886813602144551 -0.1566882158163141
Test lines on Input Image Test lines on Metric-Rectified Image

Facade

Input Image Annotated perpendicular lines Rectified Image
Before After
-0.3375580434458507 -0.07044164273136219
0.19092856775813685 0.13983925436430292
-0.23265163992207852 -0.06816308628712656
Test lines on Input Image Test lines on Metric-Rectified Image

Tile_3

Input Image Annotated perpendicular lines Rectified Image
Before After
0.3456068983416694 -0.07252476024672082
0.6054144165608599 -0.007738817645441648
0.4110890741123178 -0.0045210455616184675
Test lines on Input Image Test lines on Metric-Rectified Image

Brief description of the implementation

The metric rectification matrix is recovered using more than five pairs of perpendicular lines. The process is basically identical to the metric rectification of q2.py, except that it only has perpendicular line pairs.

  1. Identify Orthogonal Lines: Annotate the image to identify five sets of originally orthogonal lines.
  2. Recover Line Equations: For each set of orthogonal lines, recover their equations by computing the cross product of the corresponding points. Denote the recovered lines as \(l'\) and \(m'\).
  3. Find Conic Dual to Circular Points: For each pair of lines, solve for the conic dual to the circular points using the relation: \(l'^T C^*_{\infty}{}' m' = 0\)
  4. Affine Rectified Conic: The conic can be expressed as: \(C^*_{\infty} = \begin{bmatrix} a & \frac{b}{2} & \frac{d}{2} \\ \frac{b}{2} & c & \frac{e}{2} \\ \frac{d}{2} & \frac{e}{2} & f \end{bmatrix}\). The equation becomes \(A c = 0\), where \(c = [a, b, c, d, e, f]^T\). The conic can be determined by Singular Value Decomposition. The solution is the null space of \(A\).
  5. Metric Rectification: Compute the SVD of the conic. Then, find the homography. \(C^*_{\infty} = H C^*_{\infty}{}' H^T\). The solution is: \(H = \begin{bmatrix} \sqrt{\sigma_1^{-1}} & 0 & 0 \\ 0 & \sqrt{\sigma_2^{-1}} & 0 \\ 0 & 0 & 1 \end{bmatrix} U^T\) Here, \(\sigma_1\) and \(sigma_2\) are the singular values from the SVD, and \(U\) is the orthogonal matrix obtained from the decomposition.

Q5: Bonus: More Planar Homography from Point Correspondences

My wedding photos posted in a movie theater.

Original Image
Generated Image