This is my attempt at automatic image matching and transformations of 2 images to create a panorama.
This task involes 4 distinct parts:
- Extract interest points from each image
- RANSAC to figure best relative transformation
- Transform images to common coordinate system
- Blend the images together
First, the feature points are extracted by using ORB implementation from OpenCV. Then, BFMatcher is used to extract the top features. The resultant set of pairs of points are sorted by distance and the top 50 best mactched points are used.
The RANSAC algorithm is implemented as follows:
- The extracted common points are arranged in combinations of 4 points in order to use them as our hypothesis.
- Iterate through the sets of 4 point pairs created and for each set (hypothesis) calculate the homography matrix.
- Using calculated homography matrix calculate the mapped points for the remaining points and compare with the points extracted. If the mapped point falls within a threshold of a certain number of pixels with the points found through ORB, then it is counted as an inlier.
- We keep count of total number inliers using a particular hypothesis. We also keep track of the best inliers and hypothesis.
- Once we have iterated through all our hypothesis we calulate the best homography matrix using the best set of inlier points that we have stored.
Once the best homography matrix is calculated, the warped image transformation of the second image is calculated in the coordinate system of the first image.
Here the two images, the original image and the warped image need to be stitched together. The algorithm first places the original image in the canvas, and then places pixels from the warped image only where the pixel value is 0 in the final image. This way a fully stitched image is obtained.
To try this yourself type this line in your command line:
python pano.py image_1.jpg image_2.jpg output.jpg
Here are some examples:
Image 1 | Image 2 | Stitched Image |
---|---|---|
![]() |
![]() |
![]() |
Image 1 | Image 2 | Stitched Image |
---|---|---|
![]() |
![]() |
![]() |