Jimmy Xu
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.
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
The next step is to annotate the pictures with corresponding points and solve for the homography matrix
By definition, perspective projection can be expressed as follows.
I referred to [1] for some guidance to set up the system of equations. I then used least-squares to solve for
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
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.
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.
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]).
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.
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].
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 labeling | RANSAC |
---|---|
As you can see, the RANSAC method performs better than matching via my manual labeling, especially in the last image.
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.
[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