Rohan Gangakhedkar.
← All projects

Optimized Image Stitching in Python

New York University

Rohan Gangakhedkar  ·  New York University

TL;DR

Feature matches between two frames give a homography. The second frame is warped onto the first, and dynamic weighted fusion dissolves the seam line that simple pasting leaves behind.

The two source frames, captured side by side.
The stitched result — little to no seam line, and the alignment holds across the overlap.
The stitched result — little to no seam line, and the alignment holds across the overlap.

Pipeline

1  ·  Grayscale and feature extraction

Both images are converted to grayscale so that SIFT can extract keypoints and descriptors.

Grayscale inputs to SIFT.

2  ·  Matching

Descriptors are matched with OpenCV’s FlannBasedMatcher, then filtered with Lowe’s ratio test to keep only confident correspondences.

Surviving matches after the ratio test.
Surviving matches after the ratio test.

3  ·  Homography and warp

The retained matches give a homography, which is applied to the right image to bring it into the left image’s frame.

The right frame warped into alignment.
The right frame warped into alignment.

4  ·  Naive addition, and its seam

Laying the left image over the warped right image produces a sharp vertical seam at the left image’s right-hand edge. It is subtle here, but clearly visible where the arrows point.

Simple addition. The seam runs vertically through the overlap.
Simple addition. The seam runs vertically through the overlap.

5  ·  Dynamic weighted fusion

Weighted fusion across the overlap removes the seam, blending the two frames into each other rather than stacking them.

The seam resolved by weighted fusion.
The seam resolved by weighted fusion.

6  ·  Corner correction

Warping leaves ragged corners. A final warp pulls the corners back to the image edges, giving the finished panorama.

Final output.
Final output.