CS194-26 Project 4: Part A


Image Warping and Mosaicing


Sean Kwan, Fall 2021

Shoot the Pictures

Shown below are the three pairs of projective transform photographs. I tried to get a wide range of photos, including nature, the interior of a room and people.

Recover Homographies

In order to recover the homography transformation H, and to create the function:

I set up the equation:

where p is the correspondence points im1_pts, p' is the correspondence points im2_pts and H is the 3x3 Homography matrix. There are 8 unknowns so I set up a system of linear equations, transforming the p'=Hp into the form Ah=b, where h is the 8 unknown elements to be solved for in the homography matrix.

In practice, although only 8 equations (4 correspondence pair points) are needed I used more than 8 equations as the images turned out better. In order to solve this I used the least squares method.

Warp the Images & Image Rectification

In order to warp the images, I used the homography matrix H computed from the previous part. As I don't want any missed points, I used inverse warping on the image I wanted modified so I had multiply all the coordinate points by the inverse of H in order to compute the perspective transform. Using these new coordinates, I used cv2.remap in order to map the image into the new shape. Below are two examples of image rectification.

Original Tile Image

Rectified Tile Image

Original Painting Image

Rectified Painting Image

Blend the Images into a Mosaic

I reused some code from Project 2, in order to use a Laplacian pyramid to provide a smooth transition in the mosaic images. I also preprocessed the images to pad extra space, as I found the homography transformation would

Original Left Nature

Original Right Nature

Warped Right Nature

Blended Nature Mosaic

Original Left Room

Original Right Room

Warped Right Room

Blended Room Mosaic

Original Left Sean

Original Right Sean

Warped Right Sean

Blended Sean Mosaic

What I learned

I learned a lot about how homography works and how panormas are stitched together. I also got a better understanding of perspective transforms. Additionally, I realized how important it is to take a photo with the same settings and the same center in order to utilize the benefits of homography.