-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_create_dataset_rgbd_sift.m
85 lines (66 loc) · 2.58 KB
/
run_create_dataset_rgbd_sift.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
% Creates a single (giant) dataset of all the SIFT descriptors extracted from the dataset. The
% descriptors are concatenated as per 'Indoor Scene Segmentation using a Structured Light Sensor'.
addpath('common/');
Consts;
Params;
% Setup the sample mask.
[~, sz] = get_projection_mask();
% Setup the sample mask.
sampleMask = get_sample_grid(sz(1), sz(2), ...
params.sift.gridMargin, params.sift.stride);
F = nnz(sampleMask);
%% Load each descriptor.
D = 256;
N = consts.numImages;
allFeatures = zeros(N*F, D, 'single');
allNorms = zeros(N*F, 2, 'single');
allCoords = zeros(N*F, 2, 'single');
allImageNdxs = zeros(N*F, 1, 'single');
endNdx = 0;
%%
fprintf('\n');
for ii = 1 : N
if ~consts.useImages(ii)
continue;
end
fprintf('Loading sift descriptors (%d/%d)\r', ii, N);
% Grab the descriptors.
siftRgb = load(sprintf(consts.siftRgbFilename, params.sift.patchSize, ...
params.sift.stride, params.sift.normMethod, ii), ...
'features', 'coords', 'norms');
siftD = load(sprintf(consts.siftDepthFilename, params.sift.patchSize, ...
params.sift.stride, params.sift.normMethod, ii), ...
'features', 'coords', 'norms');
rgbdFeatures = [siftRgb.features siftD.features];
rgbdCoords = siftRgb.coords;
rgbdNorms = [siftRgb.norms siftD.norms];
% Create the image ndxs.
imageNdxs = ones(size(siftRgb.features, 1), 1) * ii;
startNdx = endNdx + 1;
endNdx = startNdx + size(rgbdFeatures, 1) - 1;
allFeatures(startNdx:endNdx, :) = single(rgbdFeatures);
allCoords(startNdx:endNdx, :) = single(rgbdCoords);
allNorms(startNdx:endNdx, :) = single(rgbdNorms);
allImageNdxs(startNdx:endNdx) = single(imageNdxs);
end
fprintf('\n');
% Truncate
allFeatures = allFeatures(1:endNdx, :);
allCoords = allCoords(1:endNdx, :);
allImageNdxs = allImageNdxs(1:endNdx);
%% Finally, save it to disk.
% outFilename = sprintf('%s\b\b\b\b_size%d.mat', ...
% sprintf(consts.siftDataset, params.sift.patchSize, params.sift.stride, params.sift.normMethod), ...
% length(consts.useNdx));
outFilename = sprintf(consts.siftDataset, params.sift.patchSize, params.sift.stride, params.sift.normMethod);
load(consts.splitsPath, 'trainNdxs', 'testNdxs');
allTrainIndics = isin(allImageNdxs, trainNdxs);
fprintf('Splitting into train and test...');
trainData = allFeatures(allTrainIndics, :);
testData = allFeatures(~allTrainIndics, :);
trainNorms = allNorms(allTrainIndics, :);
testNorms = allNorms(~allTrainIndics, :);
fprintf('DONE\n');
fprintf('Saving SIFT dataset: %s...', outFilename);
save(outFilename, 'trainData', 'testData', 'trainNorms', 'testNorms', '-v7.3');
fprintf('DONE\n');