Project 6.1: Image Warping and Mosaicing

James Lin, CS194-26-abr

This project was all about computing and utilizing homographies to warp and align images together in interesting ways.

Before starting on either part, I wrote a function that would take in manually defined correspondence points between two images and output a 3 by 3 matrix representing the homography transformation to go from the first image to the second.

Image Rectification

To make sure this homography-producing function worked, I first picked out images with planar surfaces and warped them such that a particular rectangle within the image became parallel with the image plane. For instance, take this photograph of a street corner.


I warped the image such that the squares tiles on the left wall directly faced the camera. As you can see, it works well for the center, but the distortion gets worse and worse near the edges of the image.


Another cool thing to note is that in real life, we'd probably be able to see the right sides of the door and window on the left side of the image. But, of course, the algorithm doesn't have any information about what new pixels might exist there! In fact, it assumes it's dealing with a planar surface and so stretches the edge of the wall to cover the gap.

I did something similar with this picture of paintings in a hallway.



I like this example because it explictly shows how images closer to the camera (the right one) get more pixel real-estate and hence end up becoming higher resolution in the warped version. The one far away has less pixels and ends up being blurry.

Mosaic Blending

This section involved combining semi-overlapping images of a scene into a single larger image (a mosaic). I took two pictures of my room that differed mostly in rotation (and brightness, although not on purpose).


I manually went and defined 13 point correspondences scattered around the overlapping segments, including the corners of posters, monitor, desk, etc. Then I ran the algorithm from the previous section to warp the second image to overlay on top of the first.


To soften the edges and boundaries between the individual images, I did a weighted average of the pixel values wherever the two overlapped. Weights were determined by how close a pixel was from its original image's center, so there was a gradual falloff. It also created a cool effect that made it look like the whole photo is curved inwards.

Below are two more panoramas. I took a shot of the flowers at the base of the campanile.



And here's one of Morrison Hall.



Probably the coolest thing I learned from this project (besides the homography technique itself) was how effective least squares can be with even limited data. All these alignments were done by hand, and with only a couple of points (8-12) least squares was able to produce essentially pixel perfect alignments.