-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompilePyramid.m
78 lines (63 loc) · 2.88 KB
/
CompilePyramid.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
function [ pyramid_all ] = CompilePyramid(imageFileList,dataBaseDir,textonSuffix, dictionarySize,pyramidLevels,name, params);
%function [ pyramid_all ] = CompilePyramid( imageFileList, dataBaseDir, textonSuffix, dictionarySize, pyramidLevels, canSkip )
%
% Generate the pyramid from the texton lablels
%
% For each image the texton labels are loaded. Then the histograms are
% calculated for the finest level. The rest of the pyramid levels are
% generated by combining the histograms of the higher level.
%
% imageFileList: cell of file paths
% dataBaseDir: the base directory for the data files that are generated
% by the algorithm. If this dir is the same as imageBaseDir the files
% will be generated in the same location as the image file
% textonSuffix: this is the suffix appended to the image file name to
% denote the data file that contains the textons indices and coordinates.
% Its default value is '_texton_ind_%d.mat' where %d is the dictionary
% size.
% dictionarySize: size of descriptor dictionary (200 has been found to be
% a good size)
% pyramidLevels: number of levels of the pyramid to build
% canSkip: if true the calculation will be skipped if the appropriate data
% file is found in dataBaseDir. This is very useful if you just want to
% update some of the data or if you've added new images.
fprintf('Compiling Pyramid\n');
pyramid_all = [];
for f = 1:size(imageFileList,1)
%% load image
imageFName = imageFileList{f};
[dirN base] = fileparts(imageFName);
baseFName = fullfile(dirN, base);
outFName = fullfile(dataBaseDir, sprintf('%s_pyramid_%d_%d_%d_%d_%s.mat', baseFName, dictionarySize, pyramidLevels, ...
params.max_pooling, params.sum_norm, name));
if(size(dir(outFName),1)~=0 && params.can_skip && params.can_skip_compilepyramid)
fprintf('Skipping (compile pyramid) %s\n', imageFName);
load(outFName, 'pyramid');
pyramid_all = [pyramid_all; pyramid];
continue;
end
%% load texton indices
in_fname = fullfile(dataBaseDir, sprintf('%s%s', baseFName, textonSuffix));
load(in_fname, 'texton_ind');
%% get width and height of input image
wid = texton_ind.wid;
hgt = texton_ind.hgt;
fprintf('Loaded (compile_pyramid) %s: wid %d, hgt %d\n', ...
imageFName, wid, hgt);
pyramid=sparse(1,texton_ind.data,1,1,dictionarySize);
if params.max_pooling
pyramid = (pyramid > .1);
end
if params.sum_norm
pyramid = pyramid / sum(sum(pyramid));
else
pyramid = pyramid/ norm(double(pyramid));
end
% save pyramid
save(outFName, 'pyramid');
pyramid_all = [pyramid_all; pyramid];
end % f
outFName = fullfile(dataBaseDir, sprintf('pyramids_all_%d_%d_%d_%d.mat', dictionarySize, pyramidLevels,...
params.max_pooling, params.sum_norm));
save(outFName, 'pyramid_all');
end