-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_refined_gt_onTopstl1.m
executable file
·135 lines (102 loc) · 3.39 KB
/
generate_refined_gt_onTopstl1.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
video_name = 'parachute';
extension = 'png'; % of ground truth
data_path = '/home/karim/MyCode/video_objectness/';
test_path = fullfile(data_path, 'test_data/segtrackv1/',video_name); % source
labels_path = fullfile(data_path , 'results/segtrackv1/stl/', video_name);
image_ids = cell(0,1);
test_imgs = dir( fullfile( test_path, '*.png' ));
% imageName x1, y1, x2, y2
image_size_width = 0;
image_size_height = 0;
%
dim = zeros(length(test_imgs),4);
max_w = 0;
max_h = 0;
for ind = 1:length(test_imgs)
%% new code here
img = imread( fullfile( test_path,'ground-truth', test_imgs(ind).name ));
[m,n,~] = size (img);
image_size_width = n;
image_size_height = m;
% read labels
file_label_path = fullfile(labels_path,strcat ( test_imgs(ind).name, '.txt'));
fid = fopen(file_label_path);
gt_info = textscan(fid, '%d %d %d %d %f64');
%gt_info_width = gt_info{1,3} - gt_info{1,1};
%gt_info_height = gt_info{1,4} - gt_info{1,2};
gt_bboxes = [gt_info{1,1}, gt_info{1,2}, gt_info{1,3}, gt_info{1,4}];
%gt_bboxes = [gt_info{1,1}, gt_info{1,2}, gt_info{1,3}, gt_info{1,4}];
gt_confidences = double(gt_info{1,5});
%[val idx] = max(gt_confidences);
[sortedValues,sortIndex] = sort(gt_confidences(:),'descend');
maxIndexes = sortIndex(1:4);
%gt_bboxes(maxIndexes(1),:)
%%
dim(ind,1) = gt_bboxes(maxIndexes(1),1)+1; %gt_bboxes(maxIndexes(1),:); %x1;
dim(ind,2) = gt_bboxes(maxIndexes(1),2)+1; %y1;
dim(ind,3) = gt_bboxes(maxIndexes(1),3)+1; %x2;
dim(ind,4) = gt_bboxes(maxIndexes(1),4)+1; %y2;
w = dim(ind,3) - dim(ind,1) +1 ;
h = dim(ind,4) - dim(ind,2) +1;
if w > max_w
max_w = w;
end
if h > max_h
max_h = h;
end
end
%% refine size
% %
% for ind = 1:length(test_imgs)
% w = dim(ind,3) - dim(ind,1) +1;
% h = dim(ind,4) - dim(ind,2) +1;
%
%
% if w < max_w
% % increase width
% shift = max_w - w;
% if mod(shift,2) == 0 % even
% dim(ind,3) = dim(ind,3) + shift/2 ;
% dim(ind,1) = dim(ind,1) - shift/2;
% else % odd
% sh = ceil(shift/2);
% dim(ind,3) = dim(ind,3) + sh;
% dim(ind,1) = dim(ind,1) - sh +1;
% end
% end
%
%
%
% if h < max_h
% % increase hig
% shift = max_h - h;
% if mod(shift,2) == 0 % even
% dim(ind,4) = dim(ind,4) + shift/2;
% dim(ind,2) = dim(ind,2) - shift/2;
% else % odd
% sh = ceil(shift/2);
% dim(ind,4) = dim(ind,4) + sh;
% dim(ind,2) = dim(ind,2) - sh +1;
% end
% end
%
% assert ( max_w == (dim(ind,3) - dim(ind,1) +1) );
% assert ( max_h == (dim(ind,4) - dim(ind,2)+1) );
%
% % assert ( dim(ind,1) > 0);
% assert ( dim(ind,3) < image_size_width);
%
% assert ( dim(ind,2) > 0);
% assert ( dim(ind,4) < image_size_height);
%end
%%
grounftruth_file = fullfile(test_path,strcat ('stl1-groundtruth_refined.txt'));
fid = fopen(grounftruth_file,'w+');
myformat = '%s\t%d\t%d\t%d\t%d\n';
for ind = 1:length(test_imgs)
filename = test_imgs(ind).name;
filename = strrep(test_imgs(ind).name, strcat('.',extension) , '.png');
fprintf(fid, myformat, filename, dim(ind,1), dim(ind,2), dim(ind,3), dim(ind,4));
end
fclose(fid);
close all;