Project 6a - Image Warping and Mosaicing!

Ashley Lin


The purpose of this project is to warp and rectify images such that the perspective is changed. This technique is applied in post processing panoramics or just adjusting the perspective view of the image. It works most optimally on images where the focal point did not change but the perspective was angled some other direction.

Shoot the Pictures

This section includes images I took around campus and my home with my iPhoneX camera. I took the pictures by placing my phone on a stable location and snapping a shot, then I put my finger on the top of the phone, directly above the camera and pivoit my phone around that point to try my best to maintain the focal point. This technique helps create better results in the mosaic section. In total, there are 2 frontal rectified images and 3 pairs of images used to mosaic together.

Recover Homographies

For this section, I solved for the homographic matrix which is used to transform from some points (x,y) to some other points (x', y'). For this case, I decided to do an inverse homographic matrix such that the points I passed in were the destination points and I used those to solve for the points from the source image. In this way, I could just interpolate the pixel values from the existing image. The form of the equation is as follows: p' = Hp. To set up the least squares equation, first note that it is in the form (Ah = b). I made the A matrix by vertically stacking the following matrix for every point transformation:

Thus, this A matrix has a dimension of (2*num_points x 9). The b vector is just a vector of zeros. And we are solving for the vector h (which has 9 unknowns but really 8 since we know the last value is a 1). To keep the least squares from outputting all zeros, I added an extra constraint such that the last value of h is a 1. This was done but adding an extra row to A where all values are 0's except for the right most value. Then, I added an extra value in b, which is a 1. In the end, my least squares equation looked like so (but with more rows, depending on the number of points I input though I usually just picked 4 points):

After solving for the h vector, I reshaped it to a 3x3 matrix and was able to apply the matrix to solve for corresponding points with this form. I solved for the x' and y' by dividing by w.

Warp the Images

To warp the images, I found source and destination points and computed the homography matrix between these two sets of points. Do note that the more corresponednce poitns you have, the more accurate your homographic matrix. I also made sure to maintain the ordering of the points so the points were manipulated accordingly. Afterwards, I iterated through all pixels locations of the output image and searched for its corresponding point in the source image (inverse warp) and copied over the pixel values.

Image Rectification

For this section, I applied the warp function (imwarp) as defined above to transform my images such that they appear to be viewed from a frontal perspective. To make it easier to warp the image as desired, I selected points on "rectanglar shapes" in the image and had the destination points set to be perspectively rectangular like (0,0), (1,0), (0,1), (1.1). You can see that with image rectification, the quality of the image is only as good as the resolution of the source image since the pixel values are drawn from the source. Thus, if your image was at a very very very angled view, it would be difficult to have a nice looking frontal view. This can be seen in how blurry the rectified text in the image. As a note, I think that the second images look blurry since there are very high frequencies and so aliasing in the is causing the details to look very warped and blurred.

Blend the images into a mosaic

For this section, I was able to create panoramas by applying the warping method to two images such that they points would align on some point. I rectified both images to the same location instead of just one to another so that the image would be in my desired perspective. The most naive way to stitch the two images was to just sum up the two images and clip them to the 0-255 range. However, this does not look real as there is ghosting across the two images. Another naive technique would be to crop the two images in half and stitch them together. I chose to do an extra step and the alpha blending technique from homework 3 (orapple example!) for a smooth transition between one image and the other. A more optimal way, to reduce residuals would have been laplacian blending but I was quite satisfied with my results so I stuck with alpha channel blending.

Cory Lab 125


Soda & Etcheverry

Tell us what you've learned

This project was very fun and interesting!! Since you can really see the power of data and transformations. It is cool since in practice, we tend to not take images in the most "visually appealing" perspectives and angles, but with some homographic warping, you are able to alter the original image to any desired perspective. It also brings intuition into how panoramic images are stitched together and mosaiced. I also had fun applying old techniques (the blending!) into this project to create my final blendedoutput. In the panoramas, you can see some misalignment in the images which is due to poor correspondence points (I picked points using a helper function from project 5). These points were wildy inaccuracte since I used my mouse to click on the points. An optimization could be to use edge detection to pick out features and align along those but that would be for a side project. I am sure that the panoramic function automates this with some sort of feature detection though.