CS294-26 Project 4 Image Warping and Mosaicing

Jimmy Xu

 

Overview

The goal of the first part of the project is to explore the magic of homography via two of its applications: image rectification and image mosaicing. The goal of the second part is to automate this process via feature detector, feature descriptor, and feature matching.

 

Shoot and Digitize Pictures

The first step is to take some pictures with the same center of projection (i.e. rotating, but not translating, the camera).

Bathroom

Bedroom

Lewis Hall

 

Recover Homographies

The next step is to annotate the pictures with corresponding points and solve for the homography matrix H. We need at least 4 points.

By definition, perspective projection can be expressed as follows.

[xayaza]=H3×3[x1y11],[x1^y1^1]=1za[xayaza][x^izay^izaza]=[h11h12h13h21h22h23h31h32h33][xiyi1]

I referred to [1] for some guidance to set up the system of equations. I then used least-squares to solve for H. Following this pattern, we can add more points to the giant matrix on the left.

[x1y11000x1x^1y1x1^x2y21000x2x2^y2x2^x3y31000x3x3^y3x3^x4y41000x4x4^y4x4^000x1y11x1y1^y1y1^000x2y21x2y2^y2y2^000x3y31x3y3^y3y3^000x4y41x4y4^y4y4^][h11h12h13h21h22h23h31h32]=h33[x^1x2^x3^x4^y1^y2^y3^y4^]where h33 can be set to be 1

Warp the Images and Image Rectification

Once we have the homography matrix, we can warp the image. If we set the destination to be a rectangle, we can make a plane frontal-parallel. I referred to [2] for some help with cv2.remap.

We can do the same thing for a more extreme example

 

Blend the Images into A Mosaic

I can also warp one image to another and blend them, creating an image mosaic. The overlapping region of the two images are the average of them.

 

Feature Detector

Now let's automate the process. The first step is to choose a feature detector. I used Harris Interest Point Detector. Note that the corners around the edges are filtered out.

 

Adaptive Non-Maximal Suppression

As you can see, there are way too many corners to process efficiently. I implemented Adaptive Non-Maximal Suppression (ANMS) to spatially evenly sample features with strong corner response. I used the method described in [3]. The 500 green dots are chosen due to their relatively large radius (defined in [3]).

 

Feature Descriptor

The next step is to generate a scale-invariant feature descriptor. I followed the method described in [3], except the rotational invariant. For each feature, I extracted the 40x40 patch around it, downsample to 8x8, and normalize it. Here's an example.

 

Lowe Thresholding

There are still too many features to process! I used the NN-1/NN-2 as a threshold to filter out more points, as described in [3].

 

Random Sample Consensus (RANSAC)

As a final step, I used the RANSAC method described in the lecture slides [4] to exclude the few outliers and compute the right homography. Here are the results.

Manual labelingRANSAC

As you can see, the RANSAC method performs better than matching via my manual labeling, especially in the last image.

 

Things I learned

While I think it is not too hard to grasp the idea of each step, I was still really impressed by the power of auto-stitching.

 

References

[1] https://towardsdatascience.com/estimating-a-homography-matrix-522c70ec4b2c

[2] https://stackoverflow.com/questions/46520123/how-do-i-use-opencvs-remap-function

[3] https://inst.eecs.berkeley.edu/~cs194-26/fa21/hw/proj4/Papers/MOPS.pdf

[4] https://inst.eecs.berkeley.edu//~cs194-26/fa21/Lectures/feature-alignment-and-flow.pdf