[Auto]Stitching Photo Mosaics

[Auto]Stitching Photo Mosaics

Project 5A, CS 194-26, Spring 2020

by Suraj Rampure (suraj.rampure@berkeley.edu, cs194-26-adz)


In the first half of this project, we create homographies between images, in order to warp one to be in the perspective of another. After doing this, we are able to stitch these images together using a mask, creating a panorama-type effect.


homography(pts1, pts2), warp_image(im, H)

The first step is to create a homography between points in one image and points in another. Specifically, we want to find some 3 x 3 matrix H such that maps p = [x, y, 1]T in image 1 to p′ = w ⋅ [x′, y′, 1] in image 2.

We want to minimize the loss created by our homography. Specifically, we want to minimize

An equivalent formulation, using the same constants in H, can be written as follows:

The above equation is of the form Av = b; solving for v using least squares gives us estimates of the values of a, b, c, d, e, f, g, h.

Now that we have the values of these 8 constants (and hence, know the 3 x 3 matrix H), we can warp points in one image to those in another using the specified homography.


Rectification

In order to check that my homography and warping methods were working, I rectified an image. Specifically, I took an image of a painting that was taken from an angled perspective, defined its corners, and computed a homography between the set of corners of that image and a flat rectangle. Below is the original image followed by a rectified version of it.

    

As you can see, it turns out quite well. (I took this picture at the Louvre in Paris.)


Defining Correspondences

The first step is to take images and define correspondences between them. I took 3 pairs of images, and defined between 19 and 30 correspondences on each. (The first pair is from my kitchen, the second pair is from a park near my house, and the third pair is in my backyard.)

                                  

    


Then, I computed a median correspondence, similar to what was done in Project 3. (I found that this gave better results than trying to warp image 1 into the perspective of image 2.) This produces warped versions of both images in the pair.

                                  

    


Lastly, I overlaid and aligned the warped images on top of one another.

               


The park panorama seems to have come out the best; I believe it’s because it has the least details in the region of overlap. The kitchen isn’t great, especially near on the left edge of the island. The backyard is decent but some details towards the back are imperfect (in particular, the rear pillars).


Looking forward to implementing automatic feature selection!