CS 180 Project 4: Stitching Photo Mosaics

By Ethan Jagoda

Introduction

This project explores how to use homographic transformations to stitch together a photo mosaic. As well, we use homographic transformations to warp images to rectify shapes to seem like they are from a different point of view.

Raw Images Used

These are some of the raw images I used in this project.

Berkeley Way West

Berkeley Way West Bottom

Berkeley Way West

Berkeley Way West Top

Pranav

Pranav Left

Pranav

Pranav Right

SF Skyline

SF Skyline Left

SF Skyline

SF Skyline Right

Recovering Correspondences

I used a GUI to manually select correspondences between the two images. This was done by clicking on a point in one image and then clicking on the corresponding point in the other image.

This is an example of one of the images with the correspondences marked.

Pranav Left Points

Pranav Left Points

Pranav Right Points

Pranav Right Points

Berkeley Way West Anchor Points

Berkeley Way West Bottom Points

Berkeley Way West Target Points

Berkeley Way West Top Points

Computing the homographic transformation

The homographic transformation is computed using the following equation:

Hp = p'

Where H is the homography matrix, p is a point in the source image, and p' is the corresponding point in the destination image.

Expanding this out, we get the following equation:

Homographic transformation matrix equation

Expanding this out further, we get the following equations:

Homographic transformation equations
Homographic transformation equations
Homographic transformation equations

Reframing this so that we can use the new points and old points to solve for the homography matrix, we get the following equations:

Homography matrix

To reduce the chance of overfitting, we can use more than 4 points and then solve this system of equations using least squares to get the homography matrix.

Warped Images

Here are some of the warped images I got from this technique.

Berkeley Way West Top Warped into Bottom

Berkeley Way West Top

Berkeley Way West Bottom Warped into Top

Berkeley Way West Bottom Warped into Top

Average Face Warped into Ethan

Pranav Left

Ethan Warped into Average Face

Pranav Right Warped into Left

SF Skyline Left

SF Skyline Left

SF Skyline Right

SF Skyline Right Warped into Left

Blending Images

To blend the images, we create a mask that is the same size and shape as the warped images. Then, to ensure a smooth transition, we use a dissolve factor that changes linearly with the distance from an images edge from 0 to 1. We then use this mask to blend the pixels of the two warped images together, normalizing the pixels by the mask so that the brightnesses are correct.

Here are some of the blended images and the corresponding masks I got from this technique.

Berkeley Way West

Anchor Alpha Mask

Anchor Alpha Mask

Warped Alpha Mask

Warped Alpha Mask

Blended Images

Blended Images

Pranav

Anchor Alpha Mask

Anchor Alpha Mask

Warped Alpha Mask

Warped Alpha Mask

Blended Images

Blended Images

SF Skyline

Anchor Alpha Mask

Anchor Alpha Mask

Warped Alpha Mask

Warped Alpha Mask

Blended Images

Blended Images

Rectifying Images

To rectify images, we can use the homography matrix to warp the image to a new point of view. This is useful for things like correcting perspective shift in photos.

Here are some of the rectified images I got from this technique.

Original Image

Original Tiles

Original Points

Original Tile Points

Rectified Points

Target Tile Points

Rectified Images

Rectified Tiles

Original Image

Original Presentation Screen

Original Points

Original Presentation Screen Points

Rectified Points

Target Presentation Screen Points

Rectified Images

Rectified Presentation Screen