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)
plt.figure(figsize=(10,10))
plt.imshow(img)
Out[66]:
<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)
img[dst>0.01*dst.max()]=[255,0,0]

plt.figure(figsize=(20,15))
plt.title('Harris Corner Response')
plt.subplot(2,1,1)
plt.imshow(dst, cmap='gray')
plt.subplot(2,1,2)
plt.title('Harris Corner Detector')
plt.imshow(img)
Out[85]:
<matplotlib.image.AxesImage at 0x14e1cf690>