""" Sift Matching on the university photos. """ import numpy as np import pylab as plt from common import sift from PIL import Image imname = ['data/Univ'+str(i+1)+'.jpg' for i in range(5)] im = {} kp = {} desc = {} for i in range(5): im[i] = np.array(Image.open(imname[i])) kp[i], desc[i] = sift.detect_and_compute(im[i]) print('starting matching') plt.figure("University Image SIFT Matches") matches = {} for i in range(4): plt.subplot(2,2,i+1) matches[i] = sift.match(desc[i+1],desc[i]) sift.plot_matches(im[i+1],im[i],kp[i+1],kp[i],matches[i]) plt.show()
from PIL import Image import numpy as np import pylab as plt from common import imtools from common import sift im1 = np.array(Image.open("data/climbing_1_small.jpg").convert("L")) im2 = np.array(Image.open("data/climbing_2_small.jpg").convert("L")) kp1, desc1 = sift.detect_and_compute(im1) kp2, desc2 = sift.detect_and_compute(im2) print('starting matching') matches = sift.match(desc1, desc2) plt.figure("SIFT Rock Wall 1-Side Matching") plt.gray() sift.plot_matches(im1, im2, kp1, kp2, matches) plt.show()
""" Exercise 4 Create copies of an image with different resolutions (for example by halving the size a few times). Extract SIFT features for each image. Plot and match features to get a feel for how and when the scale independence breaks down. """ from PIL import Image import numpy as np import pylab as plt from common import imtools from common import sift # Seems to break down around 8, clearly breaks down at 16. div_factor = 8 im = np.array(Image.open('data/empire.jpg').convert("L")) im_resized = imtools.imresize(im, (int(im.shape[1]/div_factor),int(im.shape[0]/div_factor))) kp1, desc1 = sift.detect_and_compute(im) kp2, desc2 = sift.detect_and_compute(im_resized) print('starting matching') matches = sift.match_twosided(desc1,desc2) plt.figure() plt.gray() sift.plot_matches(im,im_resized,kp1,kp2,matches) plt.show()