[Auto]Stitching Photo Mosaics

A CS 194-26 project 5 by Xiangtian Li, cs194-26-agr
berkeley

Part 1: Image Warping and Mosaicing

Recover Homographies

The 3*3 homography matrix has the following form

formula1

Given n pairs of points of the first image and the second image, we want to find H to minimized the following cost

formula2

Then we can use least square method to recover H

formula3

Image Warping and Rectification

We use the inverse matrix to implement warping. By multiplying the coordinates into the original image, we can get a new warping image.

As for image rectification, we simply select 4 points of the object corners in the original image and choose 4 corners in the output image to be rectangle. Below are some example images.

sign

rect_sign

paint

rect_paint

Mosaics

Below are the results

cave1 berkeley2 berkeley3
warp_berkeley1 warp_berkeley2 warp_berkeley3

result_cave_img

indoor1 indoor2 indoor3
warp_indoor1 warp_indoor2 warp_indoor3

result_indoor_img

room1 room2 room3
warp_room1 warp_room2 warp_room3

result_room_img

 

room1 room2 room3
warp_room1 warp_room2 warp_room3

result_room_img

Part2: Automatic Stitching

In this part, we simply implement a simplified version of Multi-Image Matching using Multi-Scale Oriented Patches to achieve automatic stitching.

Harris Corners

In this part, we use the corner_harris and corner_peaks functions of skimage.feature. We found that corner_peaks can result in much less points than peak_local_max does. Below I show three of the examples.

corner_ex_1 corner_ex_2 corner_ex_3
     

Adaptive Non-Maximal Suppression

The algorithm presented in the paper, Adaptive Non-Maximal Suppression(ANMS), can reduce the number of points by selecting the points with the largest , where is the minimum suppression radius of :

In experiment, we set and always select the top 500 ranked points. The corners left are shown below.

corner_ex_berkeley1 corner_ex_berkeley2 corner_ex_berkeley3
     

Feature Descriptor Extraction

We can descript the feature of points by extracting a patch centered at each point and then downsampling it to . Then we can do bias/gain normalization on the new patch. This can be done by subtracting the mean an dividing by the standard deviation. Then we vectorize the feature descriptors into shape .

Feature Matching

In this part we find the consistent points in two images. We compute the distance between the feature descriptors of points in the two images. We then sort the distance and use low ratio test: if 1-NN/2-NN is less than some threshold(in the experiment we set it to 0.6), we will consider the pair to be a match. Below we illustrate two matches.

corner_ex_match1 corner_ex_match2
   

RANSAC

There are some outliers remained in the matches. We can use RANSAC to remove them. First, we randomly choose 4 matches and compute the homography H. Then we warp all points in the first images into the second images and compute the distance between them. We define the points as inliers if their distances are less than a threshold(we set it to 1 in experiment). Iteratively do this for several times and always keep the largest set of inliers and let them to be our best matches.

Below we show some matches left after RANSAC. Having gained the matches, we can use the technics in Part1 to warp and blend the images into a panorama.

corner_ex_RANSAC1 corner_ex_RANSAC2
   

Results

Below we compare the results of the manual and automatic method.

Manual Automatic
result_cave_img result_berkeley_img
result_indoor_img result_indoor_img
result_indoor_img result_cafe_img
result_indoor_img result_city_img

Bells and Whistles

Video mosaics

We complete a video mosaic of a river with a length of 10 seconds. It can be viewed in Youtube below. To get a better view, you can set the quality to 2160p!

Reverse Rectify

We can use the warping and blending technics to create some interesting images. Since we used to rectify the image in the previous part, we can also reverse rectify some photos into a new images. Below are some examples.

rect_pika

rect_efros

What I learned

Feature matching is the most amazing part in my opinion. I am always curious about how the computer can identify different features in images. I think it is cool by computing the distance of feature patches. Also, I found that making a panorama video is of great use to extend the capability of our camera. We can just get a magnificent time-lapse by just stitching several clips together!