To align the images in the mosaic, I used the same correspondence tool from Project 3 to manually label matching features between each pair of images. This process
generated two sets of corresponding points: src_pts
for the source image and dst_pts
for the target image. Using these points, I computed the homography matrix following the
Singular Value Decomposition (SVD) approach, as outlined in the referenced paper.
For each pair of correspondence points (x1, y1) and (x2, y2), two constraint vectors are created to
form part of the system of equations:
Vector 1: [-x₁, -y₁, -1, 0, 0, 0, x₁ · x₂, y₁ · x₂, x₂]
Vector 2: [0, 0, 0, -x₁, -y₁, -1, x₁ · y₂, y₁ · y₂, y₂]
These vectors are derived by eliminating the scale factor w' in the target homogeneous coordinates, ensuring consistency across the transformation.
The resulting vectors are stacked into a matrix A
, which captures the relationship between the source and target points. Next, I passed matrix
A
through the SVD function np.linalg.svd(A)
, obtaining the matrices U
, S
, and VT
. The row of
VT
(or the column of V
) corresponding to the smallest singular value gives the solution vector v
. This vector contains
the elements of the flattened homography matrix.
Finally, I reshaped v
into a 3 × 3
matrix H
. To ensure the homography matrix is properly scaled, I divided each element of
H
by the value in its bottom-right corner. This normalized matrix H
provides the transformation needed to warp the source image into the
perspective of the target image.