CS194-26 Project 6 - Autostitching Photo Mosaics

Eilam Levitov - cs194-26-acx
This notebook runs on python 2.7

0. What is a Homography?

A Homography is a linear transformation (3×3 matrix) that maps the points in one image to the corresponding points in the other image. Homographies, and linear transformation in general, are an extremely versatile tool, as we will demonstrate in this notebook.

Consider a set of corresponding points $(x_1,y_1)$ and $(x_2,y_2)$ in two (potentially overlapping) images. Then, the Homography operator $H$ maps them in the following way:

In this part of the project (6A), I will manually select corresponding points in order to solve for the H matrix, which I will later apply on one of 2 over-lapping images to generate a mosaic.

1. Rectifiying an image (a prequel)

In the first part of the project, I will transform an image of Prof. Efros next to the projector screen to make the screen square. This will rectify the image, or more colloquially change the angle of point of view.

In [175]:
# Load image to be rectified
In [176]:
# Set up coordiantes for square
In [181]:
# Load preselected points for image
In [168]:
# Generate Homogarphy 
CPU times: user 583 µs, sys: 337 µs, total: 920 µs
Wall time: 602 µs
In [170]:
# Wrap image 
In [174]:
# THROW BACK

2. Mosaicing

In this part we get to the real juicy part - creaing a Mosaic/Panorama.
In this first example, I will show a simple demonstration of creating a panorama image from of my apartment's study room.

In [474]:
# Load initial 2 images and display
In [593]:
# Load preselected points for images
In [502]:
# Generate Homogarphy 
CPU times: user 555 µs, sys: 524 µs, total: 1.08 ms
Wall time: 1.97 ms
In [519]:
# Wrap image 
In [560]:
# Creating naive-blend mask
In [522]:
# Naive blending
In [561]:
# Creating multires-blend mask
In [530]:
# Multiresolution Blend
In [531]:
# Cropped display 

Second example - The laugavegur trail

In my second example I will use images from a trek I did over the summer in north-west Iceland.

As a side note, I highly recommend this trek! Feels like you're on Mars crossed with jurassic park :~>

In [532]:
# Load initial 2 images and display
In [533]:
# Load preselected points for images
In [534]:
# Generate Homogarphy 
CPU times: user 809 µs, sys: 784 µs, total: 1.59 ms
Wall time: 916 µs
In [536]:
# Wrap image 
In [563]:
# Creating mask
In [591]:
# Naive blending
In [587]:
# Loading pre-generated multires-blend mask
In [589]:
# Multiresolution Blend
In [592]:
#### Cropped display

What I've Learned

In this project I have learned the power of homographies and projective geometry. To be able to change prespective using simple linear operations is amazing to me, and I'm convinced it will come very useful in the future!