-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathviewanno.m
executable file
·103 lines (85 loc) · 3.03 KB
/
viewanno.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
function viewanno(imgset)
if nargin<1
error(['usage: viewanno(imgset) e.g. viewanno(' 39 'Main/train' 39 ') ' ...
'or viewanno(' 39 'Main/car_train' 39 ')']);
end
% change this path if you install the VOC code elsewhere
addpath([cd '/VOCcode']);
% initialize VOC options
VOCinit;
% load image set
[ids,gt]=textread(sprintf(VOCopts.imgsetpath,['../' imgset]),'%s %d');
for i=1:length(ids)
% read annotation
rec=PASreadrecord(sprintf(VOCopts.annopath,ids{i}));
% read image
I=imread(sprintf(VOCopts.imgpath,ids{i}));
if rec.segmented
% read segmentations
[Sclass,CMclass]=imread(sprintf(VOCopts.seg.clsimgpath,ids{i}));
[Sobj,CMobj]=imread(sprintf(VOCopts.seg.instimgpath,ids{i}));
end
% display annotation
if rec.segmented
subplot(311);
else
clf;
end
imagesc(I);
hold on;
for j=1:length(rec.objects)
bb=rec.objects(j).bbox;
lbl=rec.objects(j).class;
if rec.objects(j).difficult
ls='r'; % "difficult": red
else
ls='g'; % not "difficult": green
end
if rec.objects(j).truncated
lbl=[lbl 'T'];
end
if rec.objects(j).occluded
lbl=[lbl 'O'];
end
plot(bb([1 3 3 1 1]),bb([2 2 4 4 2]),ls,'linewidth',2);
text(bb(1),bb(2),lbl,'color','k','backgroundcolor',ls(1),...
'verticalalignment','top','horizontalalignment','left','fontsize',8);
if isfield(rec.objects(j),'actions')
albl='';
for k=1:VOCopts.nactions
if rec.objects(j).actions.(VOCopts.actions{k})
if ~isempty(albl)
albl=[albl '+'];
end
albl=[albl VOCopts.actions{k}];
end
end
text(bb(3),bb(4),albl,'color','k','backgroundcolor',ls(1),...
'verticalalignment','bottom','horizontalalignment','right','fontsize',8);
end
for k=1:length(rec.objects(j).part)
bb=rec.objects(j).part(k).bbox;
plot(bb([1 3 3 1 1]),bb([2 2 4 4 2]),[ls ':'],'linewidth',2);
text(bb(1),bb(2),rec.objects(j).part(k).class,'color','k','backgroundcolor',ls(1),...
'verticalalignment','top','horizontalalignment','left','fontsize',8);
end
end
hold off;
axis image off;
title(sprintf('image: %d/%d: "%s" (red=difficult, T=truncated, O=occluded)',...
i,length(ids),ids{i}),'interpreter','none');
if rec.segmented
subplot(312);
imshow(Sclass,CMclass);
axis image;
axis off;
title('segmentation by class');
subplot(313);
imshow(Sobj,CMobj);
axis image;
axis off;
title('segmentation by object');
end
fprintf('press any key to continue with next image\n');
pause;
end