Beispiel #1
0
    def match(image1, image2, visualize=False):
        """ Match features in 2 images """

        print('comparing ', image1, image2)
        locs1, desc1 = sift.read_features_from_file(
            SiftRunner.__get_sift_id__(image1))
        locs2, desc2 = sift.read_features_from_file(
            SiftRunner.__get_sift_id__(image2))
        scores = sift.match_twosided(desc1, desc2)

        if visualize:
            im1 = array(Image.open(image1).convert('L'))
            im2 = array(Image.open(image2).convert('L'))

            fig = figure()
            grid = GridSpec(2, 2)
            fig.add_subplot(grid[0, 0])
            sift.plot_feature(im1, locs1)
            fig.add_subplot(grid[0, 1])
            sift.plot_feature(im2, locs2)
            fig.add_subplot(grid[1, :])
            sift.plot_matches(im1, im2, locs1, locs2, scores, show_below=False)
            show()

        return scores
def plot_kpm(img1,img2,mode='string',less=0, from_index=-1, to_index=-1):
    if mode == 'string':
        img1 = ImageObject(img1)
        img2 = ImageObject(img2)
    im1, im2, matchscores,qom,MatchPercent = get_kpm(img1,img2, mode,less, from_index, to_index)
    
    loc1, desc1 = get_descriptors(img1)
    loc2, desc2 = get_descriptors(img2)
    
    sift.plot_matches(im1,im2,loc1,loc2,matchscores)
    image_module.remove_temp_files_img(img1)
    image_module.remove_temp_files_img(img2)
    
Beispiel #3
0
    #sift.process_image(imname1,'empire.sift')
    l1, d1 = sift.read_features_from_file('empire.sift')

    imname2 = 'tansuoyemian.png'
    #imname2 = imname1

    im2 = array(Image.open(imname2).convert('L'))
    #sift.process_image(imname2,'empire2.sift')
    l2, d2 = sift.read_features_from_file('empire2.sift')

    matches = sift.match_twosided(d1, d2)
    print matches
    sift.plot_features(im1, l1, circle=True)

    show()

    sift.plot_features(im2, l2, circle=True)
    show()

    #sift.plot_matches(im2,im1,l2,l1,matches)
    #sift.plot_matches(im2,im2,l2,l2,matches)
    print l1
    print l1[1][0], l1[1][1]
    print l2
    print l2[1][0]
    sift.plot_matches(im1, im2, l1, l2, matches)
    print l2
    print l2[1][0]
    gray()
    show()
else:
#  im1f = '../data/sf_view1.jpg'
#  im2f = '../data/sf_view2.jpg'
  im1f = '../data/crans_1_small.jpg'
  im2f = '../data/crans_2_small.jpg'
#  im1f = '../data/climbing_1_small.jpg'
#  im2f = '../data/climbing_2_small.jpg'
im1 = array(Image.open(im1f))
im2 = array(Image.open(im2f))

sift.process_image(im1f, 'out_sift_1.txt')
l1, d1 = sift.read_features_from_file('out_sift_1.txt')
figure()
gray()
subplot(121)
sift.plot_features(im1, l1, circle=False)

sift.process_image(im2f, 'out_sift_2.txt')
l2, d2 = sift.read_features_from_file('out_sift_2.txt')
subplot(122)
sift.plot_features(im2, l2, circle=False)

#matches = sift.match(d1, d2)
matches = sift.match_twosided(d1, d2)
#print '{} matches'.format(len(matches.nonzero()[0]))

figure()
gray()
sift.plot_matches(im1, im2, l1, l2, matches, show_below=True)
show()
featname = ['../pcv_data/data/Univ' + str(i + 1) + '.sift' for i in range(5)]
imname = ['../pcv_data/data/Univ' + str(i + 1) + '.jpg' for i in range(5)]
l = {}
d = {}
for i in range(5):
    sift.process_image(imname[i], featname[i])
    l[i], d[i] = sift.read_features_from_file(featname[i])
matches = {}
for i in range(4):
    matches[i] = sift.match(d[i + 1], d[i])
    # visualize the matches (Figure 3-11 in the book)
for i in range(4):
    im1 = array(Image.open(imname[i]))
    im2 = array(Image.open(imname[i + 1]))
    figure()
    sift.plot_matches(im2, im1, l[i + 1], l[i], matches[i], show_below=True)
'''def convert_points(j):
  ndx = matches[j].nonzero()[0]
  fp = homography.make_homog(l[j+1][ndx,:2].T)
  ndx2 = [int(matches[j][i]) for i in ndx]
  tp = homography.make_homog(l[j][ndx2,:2].T)
  return fp,tp'''


# function to convert the matches to hom. points
def convert_points(j):
    ndx = matches[j].nonzero()[0]
    fp = homography.make_homog(l[j + 1][ndx, :2].T)
    ndx2 = [int(matches[j][i]) for i in ndx]
    tp = homography.make_homog(l[j][ndx2, :2].T)
Beispiel #6
0
d = {}
for i in range(5):
    sift.process_image(imname[i], featname[i])
    l[i], d[i] = sift.read_features_from_file(featname[i])
    l[i][:,[0,1]] = l[i][:, [1,0]]  #x,y -> row,col
            
matches = {}
for i in range(4):
    matches[i] = sift.match(d[i+1], d[i])

#表示する
im = [np.array(Image.open(imname[i]).convert('L')) for i in range(5)]
for i in range(4):
    plt.figure(i+1)    
    plt.gray()
    sift.plot_matches(im[i+1], im[i], l[i+1], l[i], matches[i],locs_order_xy=False)


# RANSACを対応点に適用
#対応点を同次座標の点に変換する関数
def convert_points(j):
    ndx = matches[j].nonzero()[0]
    fp = homography.make_homog(l[j+1][ndx, :2].T)
    ndx2 = [int(matches[j][i]) for i in ndx]
    tp = homography.make_homog(l[j][ndx2, :2].T)
    return fp, tp

#ホモグラフィーを推定
model = homography.RansacModel()

#今回は画像0~4のうち、画像2が中心の画像として考える
from pylab import *
from numpy import *
from PIL import Image

import sift

imname1 = 'C:\Users\HASEE\Desktop\climbing_1_small.jpg'
imname2 = 'C:\Users\HASEE\Desktop\climbing_2_small.jpg'

# 处理并将结果保存到文件中
sift.process_image(imname1, imname1 + '.sift')
sift.process_image(imname2, imname2 + '.sift')

# 读取特征进行匹配
l1, d1 = sift.read_features_from_file(imname1 + '.sift')
l2, d2 = sift.read_features_from_file(imname2 + '.sift')
matchscores = sift.match_twosided(d1, d2)

# 加载并会图
im1 = array(Image.open(imname1))
im2 = array(Image.open(imname2))

sift.plot_matches(im1, im2, l1, l2, matchscores, show_below=True)
show()
Beispiel #8
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sift

featname = ['Univ'+str(i+1)+'.sift' for i in range(5)]
imname = ['Univ'+str(i+1)+'.jpg' for i in range(5)]
l = {}
d = {}
for i in range(5):
  sift.process_image(imname[i],featname[i])
  l[i],d[i] = sift.read_features_from_file(featname[i])

matches = {}
for i in range(4):
  matches[i] = sift.match(d[i+1],d[i])

from PIL import Image
from numpy import *
from pylab import *

im = [array(Image.open(imname[i]).convert('L')) for i in range(5)]
for i in range(4):
  figure()
  gray()
  sift.plot_matches(im[i+1],im[i],l[i+1],l[i],matches[i])
show()
import os
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt

im1name = 'pic1.JPG'
im2name = 'pic2.JPG'

im1 = np.array(Image.open(im1name).convert('L'))
im2 = np.array(Image.open(im1name).convert('L'))
print('Read images complete')
print('dimensions of images: ')
print('im1: ',im1.shape)
print('im2: ',im2.shape)

sift.process_image(im1name, 'pic1.sift')
sift.process_image(im2name, 'pic2.sift')
print('processed images')
l1, d1 = sift.read_features_from_file('pic1.sift')
l2, d2 = sift.read_features_from_file('pic2.sift')

print('shape of locs var1: ',l1.shape)
print('shape of locs var2: ',l2.shape)
matches = sift.match_twosided(d1,d2)
print('Matches variable dimensions: ',matches.shape)
print('plotting')
plt.figure()
plt.gray()
sift.plot_matches(im1, im2, l1, l2, matches)
plt.show()
Beispiel #10
0
    xx, yy = x.flatten(), y.flatten()
    print xx.shape
    frame = np.array([xx, yy, scale*np.ones(xx.shape[0]), np.zeros(xx.shape[0])])
    print frame.shape
    np.savetxt('tmp.frame', frame.T, fmt='%03.3f')

    if force_orientation:
        cmmd = str('sift '+imagename+' --output='+resultname+" --read-frames=tmp.frame --orientations")
    else:
        cmmd = str('sift '+imagename+' --output='+resultname+" --read-frames=tmp.frame")
    os.system(cmmd)
    print 'processed', imagename, 'to', resultname


if __name__=='__main__':
    """可以使用欧几里得距离来计算dsift之间的距离"""
    process_image_dsift('/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_1_small.jpg', 'climbing_1.sift', 90, 40, True)
    process_image_dsift('/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_2_small.jpg', 'climbing_2.sift', 90, 40, True)
    l1, d1 = sift.read_feature_from_file('climbing_1.sift')
    l2, d2 = sift.read_feature_from_file('climbing_2.sift')

    print 'starting matching'
    matches = sift.match_twosided(d1, d2)

    plt.figure()
    plt.gray()

    img1 = np.array(Image.open('/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_1_small.jpg').convert('L'))
    img2 = np.array(Image.open('/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_2_small.jpg').convert('L'))
    sift.plot_matches(img1, img2, l1, l2, matches)
    plt.show()
Beispiel #11
0
import imtools

if len(sys.argv) >= 3:
    im1f, im2f = sys.argv[1], sys.argv[2]
else:
    im1f = '/Users/thakis/src/PCV/data/sf_view1.jpg'
    im2f = '/Users/thakis/src/PCV/data/sf_view2.jpg'
im1 = array(Image.open(im1f).convert('L'))
im2 = array(Image.open(im2f).convert('L'))

sift.process_image(im1f, 'out_sift_1.txt')
l1, d1 = sift.read_features_from_file('out_sift_1.txt')
figure()
gray()
sift.plot_features(im1, l1, circle=True)

sift.process_image(im2f, 'out_sift_2.txt')
l2, d2 = sift.read_features_from_file('out_sift_2.txt')
figure()
gray()
sift.plot_features(im2, l2, circle=True)

#matches = sift.match(d1, d2)
matches = sift.match_twosided(d1, d2)
print '{} matches'.format(len(matches.nonzero()[0]))

figure()
gray()
sift.plot_matches(im1, im2, l1, l2, matches, show_below=False)
show()
Beispiel #12
0
l = {}
d = {}
for i in range(5): 
   # sift.process_image(imname[i],featname[i])
    l[i],d[i] = sift.read_features_from_file(featname[i])

matches = {}
for i in range(4):
    matches[i] = sift.match(d[i+1],d[i])

# visualize the matches (Figure 3-11 in the book)
for i in range(4):
    im1 = array(Image.open(imname[i]))
    im2 = array(Image.open(imname[i+1]))
    figure()
    sift.plot_matches(im2,im1,l[i+1],l[i],matches[i],show_below=True)


# function to convert the matches to hom. points
def convert_points(j):
    ndx = matches[j].nonzero()[0]
    fp = homography.make_homog(l[j+1][ndx,:2].T) 
    ndx2 = [int(matches[j][i]) for i in ndx]
    tp = homography.make_homog(l[j][ndx2,:2].T) 
    
    # switch x and y - TODO this should move elsewhere
    fp = vstack([fp[1],fp[0],fp[2]])
    tp = vstack([tp[1],tp[0],tp[2]])
    return fp,tp