-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathexample.py
65 lines (50 loc) · 1.35 KB
/
example.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
#coding:utf-8
#一个example,选出1.bmp里面相似的图像
from imagecluster.feature import get_feature
from imagecluster.calculate import Similar
from imagecluster.blackpoint import BlackPoint
from PIL import Image
from PIL import ImageDraw
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from imagecluster.shape import Shape
path = "demo.jpg"
resize = (128,128)
my_image = Image.open(path).resize(resize)
patterns,feature=get_feature(path,resize=resize)
def picture(image,exampless,colors):
"""
:param img:
:param example:
:return:
"""
plt.imshow(image)
ax = plt.gca()
i = 0
for examples in exampless:
for exa in examples:
rect = Rectangle((exa.left_top.x,exa.left_top.y), exa.right_bottom.x-exa.left_top.x,
exa.right_bottom.y - exa.left_top.y, fill=None, color=colors[i],linewidth=3)
ax.add_patch(rect)
i += 1
plt.show()
#plt.clf()
#example1
example = patterns[0]
example_feature = feature[0]
#example2
example2 = patterns[2]
example_feature2 = feature[2]
#
test = patterns
test_feature = feature
ok = []
ok2 = []
for i in range(len(test_feature)):
res = Similar.similar(example_feature,test_feature[i],"ecl")
if res > 0.9:
ok.append(test[i])
res = Similar.similar(example_feature2, test_feature[i], "ecl")
if res > 0.9:
ok2.append(test[i])
picture(my_image,[ok,ok2],colors=["blue","red"])