CS 194 Project 4a

Image Warping

by Alfredo Santana

Overview

In the first part of this project, I took many pictures and recovered the homography of points of the pictures. Then using the homography, I warped images, rectified images, and blended the images into a mosaic.

Shooting the pictures

For this project I used my iPhone with AE/AF locked to capture the following pictures.

My Bedroom

My Bedroom

Front yard

Front yard

Recover Homographies

To recover the homographies of my pictures, I selected 8 points in both of my pictures, so that I could construct an overdetermined system of linear equations.

8 selected points

8 selected points

8 selected points

8 selected points

Once I selected all my corresponding points, I constructed a matrix similar to the one below, and I used least squares (np.linalg.lstsq) to solve for the coefficients in the homography matrix. Image from this source.

Homography Matrix

Warp the images

To warp the images, I made the warpImage(im, H) function, which takes the image that will get warped and the homography matrix H. Inside of warpImage I construct a matrix with all the x and y coordinates of the image passed in. I then do matrix multiplication between this newly constructed matrix and H in order to warp the image. I then use cv2.remap to interpolate the result of warpImage.

Outside Warped

Room Warped

Image Rectification Results

Outside Rectified

Blend the Images into a Mosaic

What I learned

The most important thing I learned during this project was how to manually compute the homography matrix. It was really interesting learning the math behind it, and it was a great feeling being able to make our own computeH function and not have to use the built-in cv2.findhomography function.