HTML generated from Jupyter notebook: image-matching.ipynb

Lab 6 - Image matching via local feature detection

The goal of this lab is to experiment with image matching via local feature detection.

Goal: Image matching using local features

In this notebook, I have provided code for 1) corner detection and 2) SIFT feature computation. You will be using SIFT features to compute a match score between two images. Details are provided below.

Please Submit via Blackboard.

In [20]:
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt 
%matplotlib inline

Test Image

In [66]:
img_file = 'cn-tower-1.jpg'
#img_file = 'cb.png'

img = cv2.imread(img_file)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
<matplotlib.image.AxesImage at 0x137840710>

Finding interest points using Harris Corner Detector

In [85]:
img = cv2.imread(img_file)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
src = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
src = np.float32(src)

blocksize = 2 # size of the neighbourhood considered for corner detection
ksize = 3 # size of the Sobel kernel (a.k.a. the aperture parameter of the Sobel derivative)
k = 0.04 # Harris detector parameter used in the corner response equation $R = det(M) - k (trace(M))^2$
dst = cv2.cornerHarris(src, blocksize, ksize, k)
dst = cv2.dilate(dst, None)

plt.title('Harris Corner Response')
plt.imshow(dst, cmap='gray')
plt.title('Harris Corner Detector')
<matplotlib.image.AxesImage at 0x14e1cf690>