HW1: Projective Geometry and Homography

Q1: Affine Rectification (30 points)

Input Images and Output Images

Name Input Image Annotated parallel lines on input image Affine-Rectified Image Annotated Affine-Rectified Image
book1
chess1
facade
custom1
custom2

Evaluate Angles (more precisely, the cosines) of at least another 2 pairs of parallel lines before and after rectification.

Name Before After Test Image Test Image (after rectification)
book1 0.9503 0.9999 1.0000 0.9999
chess1 0.9997 0.9790 0.9999 1.0000
facade 0.9999 0.8178 0.9999 0.9999
custom1 0.9689 0.9999 0.9999 0.9999
custom2 0.4788 0.9998 0.9999 0.9999

Description of implementation

Algorithm:

  1. Identify 2 pairs of parallel lines by manually annotating 2 points for each line in the image.

  2. Store the pixel coordinates and add a column of ones to convert them to homogeneous space.

  3. Find the lines corresponding to these points using the cross product.

  4. Compute the intersection points of each pair of lines: $$ p1 = l{11} \times l_{12}, \quad p2 = l{21} \times l_{22} $$

  5. Determine the line at infinity by finding the cross product of the intersection points:

    $$ l_{\infty} = p_1 \times p_2 $$

  6. Apply a transformation to map l_{\infty} to the ideal line. The homography matrix is: $$ \mathbf{H} = \begin{bmatrix} 1 & 0 & 0 \ 0 & 1 & 0 \ l_1 & l_2 & l_3 \end{bmatrix} $$

  7. Warp the original image using H to perform affine rectification.

Q2: Metric Rectification (40 points)

Input Images and Output Images

Name Input Image Annotated parallel lines on input image Affine-Rectified Image Annotated Affine-Rectified Image
book1
chess1
facade
custom1
custom2

Evaluate Angles (more precisely, the cosines) of at least another 2 pairs of parallel lines before and after rectification.

Name Before After Test Image Test Image (after rectification)
book1 -0.4058 0.4449 0.0009 -0.0858
chess1 -0.6685 0.0211 -0.0448 -0.0096
facade 0.1918 -0.1065 -0.0461 0.0107
custom1 0.5437 -0.2881 0.0062 0.0212
custom2 -0.0183 -0.0145 0.0082 -0.0124

Description of implementation

Algorithm
  1. Affine Rectification: First, Perform affine rectification to obtain the affine-rectified image using the transformation matrix.
  2. Annotate Perpendicular Lines: Then, annotate two pairs of perpendicular lines in the original image, each defined by two points in pixel coordinates.
  3. Convert Points and Compute Lines: Convert each point to homogeneous coordinates and apply the affine transformation: pi^{\prime}=H{\mathrm{affine}} p_i. Compute the line equation for each pair of transformed points using the cross product: \ell^{\prime}=p_1^{\prime} \times p_2^{\prime}. This results in four lines representing two pairs of perpendicular lines in the affine-rectified image.

  4. Compute the Transformed Circle Conic: For two perpendicular lines, the relation $l^TCm=0$ gives the matrix equation: $$ A=U \Sigma V^T $$

  5. Compute the Rectification Matrix, the rectification matrix is: H_{\text {rect }}=\operatorname{diag}\left(1 / \sqrt{\sigma_1}, 1 / \sqrt{\sigma_2}, 1\right) V^T

  6. Apply Metric Rectification to the affine-rectified image to obtain the metric rectified image:

$$ x^{\prime \prime}=H_{\text {rect }} x^{\prime} $$

Q3: Planar Homography from Point Correspondences (30 points)

original Image Perspective Image Overlaid Image

Description of implementation

Algorithm
  1. Annotate Corner Points Annotate the four target corner points on the perspective image in pixel coordinates. The corresponding source corner points from the normal image are its four corners.

  2. Compute Homography Matrix Convert the source and target points to homogeneous coordinates. The transformation satisfies the relation $$ $p^{\prime} \equiv H p$. $$ Each correspondence provides 2 independent equations, forming matrix A. Solve Ah = 0 using SVD to get the homography matrix H, reshaped from the null vector h.

  3. Apply Homography Apply the homography matrix H to each point in the normal image to warp and overlay it onto the perspective image.