No description has been provided for this image

CSCI 3240U --- Computer Vision I¶

Lab 8 --- Homography and Image Stitching¶

Faisal Z. Qureshi
Faculty of Science, Ontario Tech University
Oshawa ON Canada
http://vclab.science.ontariotechu.ca

Fall 2026

Copyright information¶

© Faisal Qureshi

License¶

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Outline¶

Consider the following image pair

No description has been provided for this image No description has been provided for this image

You are asked to pick at least four correspondences in both images. E.g., you can pick four points $(x^l_i,y^l_i)$ in the left image and then you can pick the corresponding locations $(x^r_i,y^r_i)$ in the right image in the same order. Here $i > 3$. Given these correspondences, estimate the homography matrix between the two set of images, and use this matrix to stitch the two images into a single image.

Picking locations in an image¶

Use the following code to pick locations on an image as seen below

No description has been provided for this image

Modify the code as needed to record the $(x,y)$ locations.

In [33]:
%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import cv2 as cv
import numpy as np
In [34]:
class PointPicker:
    def __init__(self, imgplot, img, color=(255,0,0), radius=20, thickness=20):
        self.imgplot = imgplot
        self.img = img
        self.color = color
        self.radius = radius
        self.thickness = thickness
        self.cid = imgplot.figure.canvas.mpl_connect('button_press_event', self)
    
    def __call__(self, event):
        if event.inaxes != self.imgplot.axes: 
            return
        ix = event.xdata
        iy = event.ydata
        print(f'x={ix}, y={iy}')
        self.img = cv.circle(self.img, (int(ix), int(iy)), self.radius, self.color, self.thickness)
        
        imgplot.set_array(self.img)
        self.imgplot.figure.canvas.draw()

img=cv.imread('1-left.jpeg')        
        
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
imgplot = plt.imshow(img)
point_picker = PointPicker(imgplot, img)
plt.show()

Task¶

  • Load left image (1-left.jpeg) and pick at least four points in order.
  • Load right image (1-right.jpeg) and pick the corresponding locations.
  • Use the correspondences to estimate homography.
  • Use the homography to stitch the images together.

Some outdoor photography¶

  • The above image exhibits strong parallex. You may consider going for a walk and taking an image pair of your favorite neighbourhood landscape. Try not to translate the camera, just rotate in place.

Useful information¶

  • Least squares fitting
  • RANSAC
  • Homography
  • Image sampling

Bonus¶

  • Try stitching on different image pairs.
  • Can you stich more than one images to create a panorama?

Submission¶

Include code and stiched image single jupyter notebook. Submit via canvas.

No description has been provided for this image
In [ ]: