-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_database_txt_dir.m
44 lines (35 loc) · 1.51 KB
/
read_database_txt_dir.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
function [database] = read_database_txt_dir(rt_data_dir)
%=========================================================================
% inputs
% rt_data_dir -the rootpath for the database. e.g. '../data/caltech101'
% outputs
% database -a tructure of the dir
% .path pathes for each image file
% .label label for each image file
% written by Jianchao Yang(¡Á¡Á¡Á¡Á)
% Mar. 2009, IFP, UIUC
%=========================================================================
fprintf('dir the database...');
subfolders = dir(rt_data_dir);
database = [];
database.imnum = 0; % total image number of the database
database.cname = {}; % name of each class
database.label = []; % label of each class
database.path = {}; % contain the pathes for each image of each class
database.nclass = 0;
for ii = 1:length(subfolders),
subname = subfolders(ii).name;
if ~strcmp(subname, '.') & ~strcmp(subname, '..'),
database.nclass = database.nclass + 1;
database.cname{database.nclass} = subname;
frames = dir(fullfile(rt_data_dir, subname, '*.txt'));
c_num = length(frames);
database.imnum = database.imnum + c_num;
database.label = [database.label; ones(c_num, 1)*database.nclass];
for jj = 1:c_num,
c_path = fullfile(rt_data_dir, subname, frames(jj).name);
database.path = [database.path, c_path];
end;
end;
end;
disp('done!');