Project 5: (Auto)Stitching Photo Mosaics

Part 1: Image Warping and Mosaics

Computing Homography

This derivation was really helpful for understanding not only what the system of equations to solve was, but how to set it up.

Image Rectification

After computing the homography, we can warp the images (in a similar manner to how we did in Project 3). One key issue I had was using forward warping instead of inverse warping; this caused the output to have black dots/patches scattered throughout.

I defined the point correspondences to be the rectangular surface in the original image, and the other to be a “frontal” rectangle/square as appropriate.

I did have issues with figuring out how to shift the pixels after swapping to inverse warping, which is why (I think) the cardboard box image gets cut off on the left side.

Original Frontal-planar

Mosaics

I had a lot of issues using numpy to add padding to the image, and couldn’t really figure out the bug. I’ll fix it up by the time the second part is due.

For example, I warped image A to image B’s perspective by mapping the door, the painting, and the edge of the TV in the correspondence.

Image A Image B
No padding (position preserved) Padding by adjusting shape

Chosen image (position is preserved, but due to lack of padding the warped image, the interesting part is cut off)

Stacked version of images A and B. I used np.maximum to combine the two images, so the edges are very obvious in this output.

Failures / bugs

I created the new image with np.zeros(rows, columns, 3), and attempted to pad by increasing rows and columns by a certain shift, calculated by finding the difference between image size and the point coordinates resulting from polygon(). To my surprise, this changed the points mapping in the resulting image, even though I’d only changed the image shape, so that the positioning would be off and stacking would no longer work correctly ):

Example with attempt to pad and then stack (looks as if no warping happened)

Ultimately, I decided to stop with that rabbithole for now.