-
Notifications
You must be signed in to change notification settings - Fork 0
/
untitled3.py
69 lines (52 loc) · 2.06 KB
/
untitled3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from image_match.goldberg import ImageSignature
import fnmatch
import numpy
gis = ImageSignature()
p1 = "C:\Users\Haowen\Desktop\project\sift-matlab-exp\siftDemoV4\data"
c = "\\"
d = "r"
print len(fnmatch.filter(os.listdir(p1), '*.png'))
mat = numpy.zeros(shape=(len(fnmatch.filter(os.listdir(p1), '*.png'))+1,len(fnmatch.filter(os.listdir(p1), '*.png'))+1))
files = os.listdir(p1)
for f1 in files:
if os.path.splitext(f1)[1] == '.png':
f11 = p1+c+f1
a = gis.generate_signature(f11)
name1,ext = os.path.splitext(f1)
print name1
for f2 in files:
if os.path.splitext(f2)[1] == '.png':
f12 = p1+c+f2
b = gis.generate_signature(f12)
name2,ext = os.path.splitext(f2)
if int(name2)>int(name1):
mat[name1,name2] = gis.normalized_distance(a, b)
# if name1 == '3':
# print 'name1 == 3'
# print name1
# print name2
# if int(name2) >10:
# print 'name2 > 10'
# print name2
# print gis.normalized_distance(a, b)
#print mat
for i in range(len(mat)):
for j in range(len(mat)):
if j<i:
mat[i,j] = mat[j,i]
elif i==j:
mat[i,j] = 1
matindex = numpy.zeros(shape=(len(fnmatch.filter(os.listdir(p1), '*.png'))+1,len(fnmatch.filter(os.listdir(p1), '*.png'))+1))
for i in range(len(mat)):
v = mat[i,:]
# print v
matindex[i,:] = sorted(range(len(v)), key=lambda x: v[x])
# print v
# print mat[i,:]
# print matindex1[i,:]
mat[i,:] = sorted(mat[i,:])
# print matindex1[i,:]
# print mat[i,:]
#print matindex
#print mat