We can compute homographies, which are projective transformations (i.e. arbitrary quadrilateral mappings). These homographies can be used to define which parts of images should look rectangular (rectification) or can be used to stitch panoramas together (to produce image mosaics) by identifying a set of at least four correspondence points between the two images to be stitched. (I found 8 points to work well)
Let's say we want to rectify the following images:
As we can see, they were not taken head-on, and thus the rectangular objects in the image do not appear as rectangles. So, we can specify four corners of the rectangle (in the northern lights picture, I chose one of the panels to act as the rectangle). Then, we can specify some nearby coordinates that form a rectangle, and use our homography to project our image into that rectangle's plane, forcing the wall decorations to appear rectangular.
Consider these two images of my kitchen:
After defining 8 corresponding points between the two, we can compute a homography, compute its inverse, then apply the inverse to the right image in order to project it into a similar coordinate system to the left image. Then, we can combine these images into a panorama:
We can use alpha blending in order to ensure that there are no seams visible.
We can do this for other images too: