def plot_kp(img, mode='string'):
    img = ImageObject(img)
    img = image_module.convert_to_pgm(img)
    img = make_keypoints(img)
    
    loc, desc = get_descriptors(img)
    im = get_image_as_array(img)
    sift.plot_features(im,loc)
    image_module.remove_temp_files_img(img)
Exemple #2
0
def plot_sift_feature(im):
    #imname = ’empire.jpg’
    #im1 = array(Image.open(imname).convert(’L’))
    tmpFile = 'tmp.sift'
    sift.process_image(im,tmpFile)
    l1,d1 = sift.read_features_from_file(tmpFile)
    figure()
    gray()
    sift.plot_features(im,l1,circle=True)
    show()
def hog_histogram(img_list, out_file, debug):

    f = open(img_list)
    filenames = f.read().splitlines()
    f.close()

    image_vector = []
    ctr = 0

    for entry in filenames:

        dsift.process_image_dsift(entry, 'tmp.sift', 20, 10, resize=(200, 200))
        l, d = sift.read_features_from_file('tmp.sift')

        if debug:
            im = array(Image.open(entry))
            sift.plot_features(im, l, True)
            show()

        image_vector.append(d.flatten().tolist())
        os.remove('tmp.sift')
        os.remove('tmp.frame')

        if not PGM:
            os.remove('tmp.pgm')

        if out_file != None:
            f = open(out_file, 'a')

            if ctr == 0:
                header = ''
                for i in range(len(image_vector[ctr])):
                    if i == 0:
                        header += str(i)
                    else:
                        header += ',' + str(i)
                f.write(header)
                f.write('\n')

            vector = ''

            for i in range(len(image_vector[ctr])):
                if i == 0:
                    vector += str(image_vector[ctr][i])
                else:
                    vector += ',' + str(image_vector[ctr][i])

            f.write(vector)
            f.write('\n')

            f.close()

        ctr += 1

    return image_vector
Exemple #4
0
def generate_sift_image(imname):
    im = array(Image.open(imname))
    removed_ext = imname[0:imname.index(".")]
    sift.process_image(imname, removed_ext + '.sift')
    l1, d1 = sift.read_features_from_file(removed_ext + '.sift')
    print d1.shape

    figure()
    gray()
    sift.plot_features(im, l1, circle=True)
    savefig(removed_ext + "_sift.png", bbox_inches="tight")
    show()
Exemple #5
0
    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')
    img1 = np.array(Image.open('/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_1_small.jpg').convert('L'))
    print 'starting matching'
    matches = sift.match_twosided(d1, d2)

    plt.figure()
    plt.gray()
    sift.plot_features(img1, l1, True)

    # 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()
Exemple #6
0
        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')
    img1 = np.array(
        Image.open(
            '/home/aurora/hdd/workspace/PycharmProjects/data/pcv_img/climbing_1_small.jpg'
        ).convert('L'))
    print 'starting matching'
    matches = sift.match_twosided(d1, d2)

    plt.figure()
    plt.gray()
    sift.plot_features(img1, l1, True)

    # 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()
Exemple #7
0
# 添加中文字体支持
# from matplotlib.font_manager import FontProperties
# font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
from matplotlib.font_manager import FontProperties
font = FontProperties(fname="/System/Library/Fonts/PingFang.ttc", size=14)

imname = '../data/empire.jpg'
im = array(Image.open(imname).convert('L'))
sift.process_image(imname, 'empire.sift')
l1, d1 = sift.read_features_from_file('empire.sift')

figure()
gray()
subplot(131)
sift.plot_features(im, l1, circle=False)
title(u'SIFT特征',fontproperties=font)
subplot(132)
sift.plot_features(im, l1, circle=True)
title(u'用圆圈表示SIFT特征尺度',fontproperties=font)

# 检测harris角点
harrisim = harris.compute_harris_response(im)

subplot(133)
filtered_coords = harris.get_harris_points(harrisim, 6, 0.1)
imshow(im)
plot([p[1] for p in filtered_coords], [p[0] for p in filtered_coords], '*')
axis('off')
title(u'Harris角点',fontproperties=font)
Exemple #8
0
from PIL import Image
from pylab import *
import sift
import sys
#import imtools

imname = 'board.jpeg'
if len(sys.argv) > 1:
  imname = sys.argv[1]

histeq = False

sift.process_image(imname, 'out_sift.txt', histeq=histeq)
l1, d1 = sift.read_features_from_file('out_sift.txt')

im1 = array(Image.open(imname).convert('L'))
if histeq:
  import imtools
  im1 = uint8(imtools.histeq(array(im1))[0])
print 'image size {}, {} features'.format(im1.shape, len(l1))

figure()
gray()
sift.plot_features(im1, l1, circle=False)
show()
Exemple #9
0
# -*- coding: utf-8 -*-
"""
Created on Wed May 14 15:31:48 2014

@author: admin
"""
import dsift,sift
import numpy as np
from PIL import Image
from pylab import *


dsift.process_image_dsift('empire.jpg','empire.sift',90,40,True)
l,d=sift.read_features_from_file('empire.sift')
im=np.array(Image.open('empire.jpg'))
sift.plot_features(im,l,True)
show()


####################################################################
Exemple #10
0
from PIL import Image
from numpy import *
from pylab import *
import os
import sift
import imtools
import pickle

testim = 'test.jpg'
rspath = 'test0.sift'

im = sift.process_image(testim,rspath)#,"--edge-thresh 5 --peak-thresh 10")
locs,decs = sift.read_features_from_file(rspath)
sift.plot_features(im,locs)
lcount = imtools.linecount(rspath)
print lcount

#testf = 'train2-test2.ares'
#fobj = open(testf,'rb')
#res = pickle.load(fobj)
#print res.shape
 def display_features(self):
     feat = sift.read_features_from_file('data/' + self.name + '/' +
                                         self.name + '_sift')
     sift.plot_features(self.img_color, feat[0])
Exemple #12
0
from PIL import Image
from numpy import *
from pylab import *
import os
from scipy import *
import sift,dsift

dsift.process_image_dsift('video/Fhist.jpg','video/FDsift.sift',30,15,True,resize=(200,200))
l,d = sift.read_features_from_file('video/FDsift.sift')

im = Image.open('video/Fhist.jpg')
im = im.resize((200,200))
im = array(im)
gray()
sift.plot_features(im,l,False)
show()
	def display_features(self):
		feat = sift.read_features_from_file('data/'+self.name+'/'+self.name+'_sift')
		sift.plot_features(self.img_color, feat[0])
Exemple #14
0
    imname1 = 'bigtu.png'
    #imname1 ='tansuodatu.png'
    im1 = array(Image.open(imname1).convert('L'))
    #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]
Exemple #15
0
from pylab import *
import sys

import sift
#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()
Exemple #16
0
import numpy as np
from PIL import Image
import pylab as pl
import dsift
import sift

dsift.process_image_dsift_2('../data/empire.jpg', 'empire.sift', 90, 40, True)
l, d = sift.read_features_from_file('empire.sift')

im = np.array(Image.open('../data/empire.jpg'))

sift.plot_features(im, l, True)

pl.show()
from pylab import *
import sys

import sift
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()
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()
accept = (accept_z > -.65) * (np.abs(accept_x) < .05)* (np.abs(accept_y) > .25) * (np.abs(accept_y) < .5)

pos_vec = pc_range * accept
color_vec = pc_color * accept

pos = np.reshape(pos_vec.T, (480, 640, 3))
img = np.reshape(color_vec.T, (480, 640, 3))

#pl.imshow(pos[:,:,2])
#pl.imshow(img)
#pl.show()

#pdb.set_trace()

im = sm.toimage(img[:,:,0])
im.save('sift/tmp_sift_img.pgm')
imagename = 'tmp_sift_img.pgm'
resultname = 'tmp_features'
os.system("sift/sift <"+imagename+">"+resultname)
#os.system('chmod og=rwx tmp_sift_img2.jpg')
#sm.imsave('tmp_sift_img.jpg', img)
#sift.process_image('tmp_sift_img2.pgm', 'tmp_features')
feat = sift.read_features_from_file('tmp_features')

sift.plot_features(img, feat[0])




Exemple #20
0
from PIL import Image
from numpy import *
import sift

sift.process_image('basmati.pgm', 'basmati.key')
l1,d1 = sift.read_features_from_file('basmati.key')
im = array(Image.open('basmati.pgm'))
sift.plot_features(im,l1)
# print full array
set_printoptions(threshold=nan)

key1 = sift.process_image('h3.jpg')
#print key
#nk = str(key).split('\n')
#print len(nk)

l1, d1 = sift.read_features(key1)
img1 = array(Image.open('h3.pgm'))
print 'got the first pic'
#print d
#print array(ravel(d1))
#print '================================================'
sift.plot_features(img1, l1)

key2 = sift.process_image('h4.jpg')
l2, d2 = sift.read_features(key2)
img2 = array(Image.open('h4.pgm'))
print 'got the second pic'
sift.plot_features(img2, l2)
#print d2
#print array(ravel(d2))
#print '================================================'

'''
key3 = sift.process_image('img3.jpg')
l3, d3 = sift.read_features(key3)
img3 = array(Image.open('img3.pgm'))
#print d3
    return array(p).T


# 计算特征
sift.process_image('book_main.jpg', 'im0.sift')
l0, d0 = sift.read_features_from_file('im0.sift')


imname = 'book_main.jpg'
im1 = array(Image.open(imname).convert('L'))
l1, d1 = sift.read_features_from_file('im0.sift')

figure()
gray()
sift.plot_features(im1, l1, circle=True)
show()




sift.process_image('book_test.jpg', 'im1.sift')
l1, d1 = sift.read_features_from_file('im1.sift')


imname = 'book_test.jpg'
im1 = array(Image.open(imname).convert('L'))
l1, d1 = sift.read_features_from_file('im1.sift')

figure()
gray()
Exemple #23
0
accept_x = np.sum((pc_range * N_x[np.newaxis, :]), axis=1)
accept_y = np.sum((pc_range * N_y[np.newaxis, :]), axis=1)
accept_z = np.sum((pc_range * N_z[np.newaxis, :]), axis=1)

accept = (accept_z > -.65) * (np.abs(accept_x) < .05) * (
    np.abs(accept_y) > .25) * (np.abs(accept_y) < .5)

pos_vec = pc_range * accept
color_vec = pc_color * accept

pos = np.reshape(pos_vec.T, (480, 640, 3))
img = np.reshape(color_vec.T, (480, 640, 3))

#pl.imshow(pos[:,:,2])
#pl.imshow(img)
#pl.show()

#pdb.set_trace()

im = sm.toimage(img[:, :, 0])
im.save('sift/tmp_sift_img.pgm')
imagename = 'tmp_sift_img.pgm'
resultname = 'tmp_features'
os.system("sift/sift <" + imagename + ">" + resultname)
#os.system('chmod og=rwx tmp_sift_img2.jpg')
#sm.imsave('tmp_sift_img.jpg', img)
#sift.process_image('tmp_sift_img2.pgm', 'tmp_features')
feat = sift.read_features_from_file('tmp_features')

sift.plot_features(img, feat[0])