Assignment 1

Roshan Roy (roshanr)

Late Days: 1

Q1. Affine Rectification

Implementation Explained

  1. Calculate lines from consecutive points

    l=p1×p2l = p_1 \times p_2

  1. For lines l1l_1 and l2l_2, calculate the intersection point x1x_1. For lines l3l_3 and l4l_4, calculate the intersection point x2x_2.

    x1=l1×l2x_1 = l_1 \times l_2

  1. Calculate the image of the line at infinity

    l=x1×x2l_{\infin} = x_1 \times x_2

  1. The homography HH such that HTLH^{-T}L becomes [0,0,1]T[0, 0, 1]^T is
    H=[100010l1l2l3]H = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ l_1 & l_2 & l_3 \\ \end{bmatrix}
  1. Warp the entire image with the homography

Tiles 5

cosine beforecosine after
0.98683276464626750.9999251970022867
0.99871910708134850.9999383464088628
original
lines annotated
image rectified
test lines annotated
test lines rectified

Tiles 3

cosine beforecosine after
0.98683276464626750.9999251970022867
0.99871910708134850.9999383464088628

original
lines annotated
image rectified

test lines annotated

test lines rectified

Facade

cosine beforecosine after
0.78423242988646910.9999781395179718
0.9999970152053780.9999869448826935

original

lines annotated
image rectified
test lines annotated
test lines rectified

Custom Image 1

cosine beforecosine after
0.9991535466648080.9992655574980497
0.99830153581502760.9992655574980497
original
lines annotated
rectified image
test lines annotated
test lines rectified

Custom Image 2

cosine beforecosine after
0.9980439366654190.9991465474980309
0.99931046781501890.9993455575680324

original
original
lines annotated
image rectified
test lines annotated
test lines rectified

Q2. Metric Rectification

Implementation Explained

  1. Calculate lines from consecutive points. There should be 8 lines.

    l=p1×p2l = p_1 \times p_2

  1. Perform affine rectification of the image.
  1. Find C{C_{\infty}^{*}}^{'} for perpendicular lines l,ml,m such that
lTCm=0{l^{'}}^T {C_{\infty}^{*}}^{'} m = 0

Since affine rectification of lines has already occurred, the matrix is expressed as:

C=[ab0bc0001]{C_{\infty}^{*}}^{'} = \begin{bmatrix} a & b & 0 \\ b & c & 0 \\ 0 & 0 & 1 \end{bmatrix}
  1. Collect 2 additional pairs of points for metric rectification since there are 2 remaining DoF. For each pair,
[l1m1l1m2+m2l2l2m2][abc]=0\begin{bmatrix} l_1m_1 & l_1m_2+m_2l_2 & l_2m_2\end{bmatrix} \begin{bmatrix} a \\ b \\ c \end{bmatrix} = 0

Setup the A matrix where each row contains a constraint from a pair of points.

  1. Solve Ax=0Ax = 0 using SVD to find C{C_{\infty}^{*}}^{'}
  1. Use SVD on C{C_{\infty}^{*}}^{'} to split it into matrices U,Σ,VTU, \Sigma, V^T. The rectification matrix HH is given by:
H=[1σ10001σ20001]UTH = \begin{bmatrix} \sqrt{\frac{1}{\sigma_{1}}} & 0 & 0 \\ 0 & \sqrt{\frac{1}{\sigma_{2}}}& 0 \\ 0 & 0 & 1 \end{bmatrix}U^T

Tiles 5

cosine beforecosine after
0.19963725801696636-0.10807147974411524
-0.008091866263126116-0.029306932732914914
original
lines annotated
image rectified
test lines annotated

test lines rectified

Tiles 3

cosine beforecosine after
0.59801439040422840.6325307814220813
-0.019320944012100630.0295500629526544
original
test lines annotated
lines annotated
test lines rectified
image rectified

Facade

cosine beforecosine after
-0.6684246986152510.6895051536253906
0.04607186861647770.01074685806717125
original
test lines annotated

lines annotated
test lines rectified
image rectified

Custom 1

cosine beforecosine after
0.55156862193909360.0900216412583554
0.165477979446080140.024742420217575188
original
lines annotated
image rectified
test lines annotated

Custom 2

cosine beforecosine after
-0.2794581244460149-0.03336564977793258
0.66954060652905320.08244873784229738

test lines rectified

original
lines annotated
rectified_image
test lines annotated
test lines rectified

Q3. Planar Homography

Implementation Details

First, we normalize the points in both images to bring it to similar scales.

For a given pair of correspondences,

x=Hxx^{'} = Hx

We introduce the constraint

x×Hx=0x^{'} \times Hx = 0

After expanding and massaging this equation (where h is an unrolled vector of 9 elements):

[000wx1Twx2Twx3Tyx1Tyx2Tyx3Twx1Twx2Twx3T000xx1Txx2Txx3Tyx1Tyx2Tyx3Txx1Txx2Txx3T000]h=0\begin{bmatrix} 0 & 0& 0& -w^{'}x_1^{T} & -w^{'}x_2^{T} & -w^{'}x_3^{T} & y^{'}x_1^{T} & y^{'}x_2^{T} & y^{'}x_3^{T} \\ w^{'}x_1^{T} & w^{'}x_2^{T} & w^{'}x_3^{T} & 0 & 0& 0 & -x^{'}x_1^{T} & x^{'}x_2^{T} & x^{'}x_3^{T} \\ y^{'}x_1^{T} & y^{'}x_2^{T} & y^{'}x_3^{T} & -x^{'}x_1^{T} & x^{'}x_2^{T} & x^{'}x_3^{T} & 0 & 0& 0 \end{bmatrix}h = 0

Note that this only gives us two constraints, not 3.

Given 4 point correspondences (H has 8 DoF), we stack the system of linear equations into the form Ah=0Ah = 0. We solve with the constraint h=1||h|| = 1 to avoid the trivial solution. Solve for h using SVD (h is the right singular vector of V).

Book on Table

normal image
perspective image
perspective image, annotated
overlaid image

Custom Image

normal image: source
perspective image: source
perspective image, annotated
overlaid image

Q4. Metric Rectification with Perpendicular Lines

Implementation Steps

  1. Calculate lines from consecutive points. Calculate all 8 lines:

    l1=p1×p2l_1 = p_1 \times p_2

  1. Find C{C_{\infty}^{*}}^{'} for perpendicular lines l,ml,m such that lTCm=0{l^{'}}^T {C_{\infty}^{*}}^{'} m = 0

    C{C_{\infty}^{*}}^{'} is of the form

    C=[abdbcedef]{C_{\infty}^{*}}^{'} = \begin{bmatrix} a & b & d \\ b & c & e \\ d & e & f \end{bmatrix}
  1. Collect 5 pairs of perpendicular points for metric rectification since there are 5 DoF, and since each pair gives one constraint. For each pair:
    [l1m1l1m2+l2m1l2m2l1m3+l3m1l2m3+l3m2l3m3][abcdef]=0\begin{bmatrix} l_1m_1 & l_1m_2+l_2m_1 & l_2m_2 & l_1m_3+l_3m_1 & l_2m_3+l_3m_2 & l_3m_3 \end{bmatrix} \begin{bmatrix} a \\ b \\ c \\ d \\e \\f \end{bmatrix} = 0
  1. Setup the A matrix where each row contains a constraint from a pair of points.
  1. Solve Ax=0Ax = 0 using SVD to find C{C_{\infty}^{*}}^{'}
  1. Use SVD on C{C_{\infty}^{*}}^{'} to split it into matrices U,Σ,VTU, \Sigma, V^T. The rectification matrix HH is given by:
H=[1σ10001σ20001]UTH = \begin{bmatrix} \sqrt{\frac{1}{\sigma_{1}}} & 0 & 0 \\ 0 & \sqrt{\frac{1}{\sigma_{2}}}& 0 \\ 0 & 0 & 1 \end{bmatrix}U^T
  1. Warp the image with this HH matrix.

Tiles 5

cosine beforecosine after
-0.0042055141371639656-0.07386339052291979
-0.19065250691171096-0.12920370791376876

original
lines annotated
image rectified
test lines annotated
test lines rectified

Custom Image

cosine beforecosine after
0.159042674592615650.17378726431444147
0.063522366136502390.09511044114149836
original

lines annotated
test lines annotated

test lines rectified
image rectified

Q5. Bonus

A picture of my old roommate’s dog Rosy on multiple Times Square billboards. Implementation is similar to that of Q3, just applied multiple times. Please refer to the code for more details.

normal image
overlaid image
perspective image
first billboard annotated
second billboard annotated