-
Notifications
You must be signed in to change notification settings - Fork 0
/
expandImg.m
executable file
·92 lines (84 loc) · 2.46 KB
/
expandImg.m
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function expandImg(pop)
query = {'rabbit';};
for i = 1:size(query, 1)
expandingImg(query{i, 1}, pop);
end
end
function expandingImg(query, pop)
selectedHE = [];
BUFF_SIZE = 100;
%% select hyperedges which has a quey in population
split_query = regexp(query, '\s', 'split');
buffer = cell(BUFF_SIZE, 1);
if length(split_query) == 1
count = 1;
for i = 1:size(pop, 1)
if sum(ismember(split_query, pop(i, 1).text)) >= 1
buffer{count, 1} = pop(i, 1);
count = count + 1;
if count == BUFF_SIZE + 1
selectedHE = [selectedHE; buffer];
count = 1;
end
end
end
else
count = 1;
for i = 1:size(pop, 1)
if sum(ismember(split_query, pop(i, 1).text)) >= length(split_query)
buffer{count, 1} = pop(i, 1);
count = count + 1;
if count == BUFF_SIZE + 1
selectedHE = [selectedHE; buffer];
count = 1;
end
end
end
end
selectedHE = [selectedHE; buffer(1:count - 1)];
temp = zeros(size(selectedHE, 1), 1);
for i = 1:size(selectedHE, 1)
temp(i, 1) = selectedHE{i, 1}.weight;
end
[B, idx] = sort(temp, 'descend');
dir_name = ['./genImg/testrabbit/'];
mkdir(dir_name);
rabbit_words = selectedHE{idx(2), 1}.text;
name = sprintf([dir_name 'test_love.jpg']);
imwrite(selectedHE{idx(20), 1}.bundle.img, name);
expandingImgImg(selectedHE{idx(20), 1}.bundle, pop);
end
function expandingImgImg(bundleIdx, pop)
selectedHE = [];
BUFF_SIZE = 100;
buffer = cell(BUFF_SIZE, 1);
count = 1;
for i=1:size(pop, 1)
aa = sum(ismember(bundleIdx.features, pop(i,1).bundle.features));
bb = aa /size(pop(i,1).bundle.features,2);
if aa >= 20 && bb > 0.4
buffer{count, 1} = pop(i, 1);
count = count + 1;
if count == BUFF_SIZE + 1
selectedHE = [selectedHE; buffer];
count = 1;
end
end
end
selectedHE = [selectedHE; buffer(1:count - 1)];
if isempty(selectedHE)
disp(['not exist']);
else
temp = zeros(size(selectedHE, 1), 1);
for i = 1:size(selectedHE, 1)
temp(i, 1) = selectedHE{i, 1}.weight;
end
[B, idx] = sort(temp, 'descend');
dir_name = ['./genImg/i2itestrabbit/'];
mkdir(dir_name);
for i = 1:size(B, 1)
name = sprintf([dir_name '%d.jpg'], i);
imwrite(selectedHE{idx(i), 1}.bundle.img, name);
end
end
end