-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocSetup_satellite.m
117 lines (106 loc) · 4.37 KB
/
vocSetup_satellite.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
function imdb = vocSetup_satellite(varargin)
% save this: save('imdb.mat', '-struct', 'ans') ;
opts.edition = '11' ;
opts.dataDir = fullfile('data','satellite') ;
opts.archiveDir = fullfile('data','archives') ;
opts.includeDetection = false ; %%
opts.includeSegmentation = true ;
opts.includeTest = false ; %%
opts = vl_argparse(opts, varargin) ;
% Download data
% if ~exist(fullfile(opts.dataDir,'Annotations')), download(opts) ; end
% Source images and classes
imdb.paths.image = esc(fullfile(opts.dataDir, 'JPEGImages', '%s.jpg')) ;
imdb.sets.id = uint8([1 2 3]) ;
imdb.sets.name = {'train', 'val', 'test'} ;
% imdb.classes.id = uint8(1:20) ;
imdb.classes.id = uint8(1:1) ;
% imdb.classes.name = {...
% 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', ...
% 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', ...
% 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'} ;
imdb.classes.name = {'building'} ;
% imdb.classes.images = cell(1,20) ;
imdb.classes.images = cell(1,1) ;
imdb.images.id = [] ;
imdb.images.name = {} ;
imdb.images.set = [] ;
index = containers.Map() ;
[imdb, index] = addImageSet(opts, imdb, index, 'train', 1) ;
[imdb, index] = addImageSet(opts, imdb, index, 'val', 2) ;
% Source segmentations
if opts.includeSegmentation
n = numel(imdb.images.id) ;
imdb.paths.objectSegmentation = esc(fullfile(opts.dataDir, 'SegmentationObjectExt', '%s.png')) ;
imdb.paths.classSegmentation = esc(fullfile(opts.dataDir, 'SegmentationClassExt', '%s.png')) ;
imdb.images.segmentation = false(1, n) ;
[imdb, index] = addSegmentationSet(opts, imdb, index, 'train', 1) ;
[imdb, index] = addSegmentationSet(opts, imdb, index, 'val', 2) ;
if opts.includeTest, [imdb, index] = addSegmentationSet(opts, imdb, index, 'test', 3) ; end
end
% Compress data types
imdb.images.id = uint32(imdb.images.id) ;
imdb.images.set = uint8(imdb.images.set) ;
for i=1:1
imdb.classes.images{i} = uint32(imdb.classes.images{i}) ;
end
% Check images on disk and get their size
imdb = getImageSizes(imdb) ;
% -------------------------------------------------------------------------
function [imdb, index] = addImageSet(opts, imdb, index, setName, setCode)
% -------------------------------------------------------------------------
j = length(imdb.images.id) ;
for ci = 1:length(imdb.classes.name)
className = imdb.classes.name{ci} ;
annoPath = fullfile(opts.dataDir, 'ImageSets', 'Main', ...
[className '_' setName '.txt']) ;
fprintf('%s: reading %s\n', mfilename, annoPath) ;
[names,labels] = textread(annoPath, '%s %f') ;
for i=1:length(names)
if ~index.isKey(names{i})
j = j + 1 ;
index(names{i}) = j ;
imdb.images.id(j) = j ;
imdb.images.set(j) = setCode ;
imdb.images.name{j} = names{i} ;
imdb.images.classification(j) = true ;
else
j = index(names{i}) ;
end
if labels(i) > 0, imdb.classes.images{ci}(end+1) = j ; end
end
end
% -------------------------------------------------------------------------
function [imdb, index] = addSegmentationSet(opts, imdb, index, setName, setCode)
% -------------------------------------------------------------------------
segAnnoPath = fullfile(opts.dataDir, 'ImageSets', 'Segmentation', [setName '.txt']) ;
fprintf('%s: reading %s\n', mfilename, segAnnoPath) ;
segNames = textread(segAnnoPath, '%s') ;
j = numel(imdb.images.id) ;
for i=1:length(segNames)
if index.isKey(segNames{i})
k = index(segNames{i}) ;
imdb.images.segmentation(k) = true ;
imdb.images.set(k) = setCode ;
else
j = j + 1 ;
index(segNames{i}) = j ;
imdb.images.id(j) = j ;
imdb.images.set(j) = setCode ;
imdb.images.name{j} = segNames{i} ;
imdb.images.classification(j) = false ;
imdb.images.segmentation(j) = true ;
end
end
% -------------------------------------------------------------------------
function imdb = getImageSizes(imdb)
% -------------------------------------------------------------------------
for j=1:numel(imdb.images.id)
info = imfinfo(sprintf(imdb.paths.image, imdb.images.name{j})) ;
imdb.images.size(:,j) = uint16([info.Width ; info.Height]) ;
fprintf('%s: checked image %s [%d x %d]\n', mfilename, imdb.images.name{j}, info.Height, info.Width) ;
end
% -------------------------------------------------------------------------
function str=esc(str)
% -------------------------------------------------------------------------
str = strrep(str, '\', '\\') ;