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()
Exemple #2
0
"""
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()
Exemple #3
0
im_paths = imtools.get_imlist(download_path)
nbr_images = len(im_paths)

im_list = []

for path in im_paths:
    im = np.array(Image.open(path).convert("L"))
    im_list.append(imtools.imresize(im,(int(im.shape[1]/2),int(im.shape[0]/2))))


matchscores = np.zeros((nbr_images,nbr_images))

for i in range(nbr_images):
    for j in range(i,nbr_images): # only compute upper triangle
        print('comparing ', im_paths[i], im_paths[j])
        l1,d1 = sift.detect_and_compute(im_list[i])
        l2,d2 = sift.detect_and_compute(im_list[j])
        matches = sift.match_twosided(d1,d2)
        nbr_matches = np.sum(matches > 0)
        print('number of matches = ', nbr_matches)
        matchscores[i,j] = nbr_matches

# copy values
for i in range(nbr_images):
    for j in range(i+1,nbr_images): # no need to copy diagonal
        matchscores[j,i] = matchscores[i,j]

threshold = 2 # min number of matches needed to create link

g = pydot.Dot(graph_type='graph') # don't want the default directed graph
from PIL import Image
from scipy import ndimage
import numpy as np
import pylab as plt
import pickle

from common import objects3d
from common import homography
from common import camera
from common import sift

im_book_frontal = np.array(Image.open('data/book_frontal.JPG'))
im_book_perspective = np.array(Image.open('data/book_perspective.JPG'))

# Compute features
l0, d0 = sift.detect_and_compute(im_book_frontal)
l1, d1 = sift.detect_and_compute(im_book_perspective)

# Match features and estimate homography
matches = sift.match_twosided(d0, d1)
ndx = matches.nonzero()[0]
fp = homography.make_homog(l0[ndx, :2].T)
ndx2 = [int(matches[i]) for i in ndx]
tp = homography.make_homog(l1[ndx2, :2].T)

# This differs from the book: Swap coordinates in the from/to points because they are row/col
# whereas the Camera plots are x/y. If they aren't swapped before goint into the
# H_from_ransac method, H will not be computed correctly for the camera translation.
fp_xy = np.array([fp[1, :], fp[0, :], fp[2, :]])
tp_xy = np.array([tp[1, :], tp[0, :], tp[2, :]])
Exemple #5
0
from PIL import Image
import numpy as np
import pylab as plt
from common import imtools
from common import sift

im = np.array(Image.open('data/empire.jpg'))
kp, desc = sift.detect_and_compute(im)
plt.figure("SIFT Key Points")
sift.plot_features(im, kp, True)
plt.show()
Exemple #6
0
"""
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()