-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheigenfaces_load.m
More file actions
40 lines (33 loc) · 1.2 KB
/
Copy patheigenfaces_load.m
File metadata and controls
40 lines (33 loc) · 1.2 KB
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
function [ I A ] = eigenfaces_load( basepath, extension, varargin )
% LOAD_IMAGES Loads images from all sub-folders
% I = LOAD_IMAGES(path, ext) loads all images with the given extension
% from all subfolders of path.
% [I A] = LOAD_IMAGES(path, ext) as above, but also returns a vector
% specifying the index of the sub directory for each image.
p = inputParser;
addRequired(p, 'basepath', @ischar);
addRequired(p, 'extension', @ischar);
% addParameter(p, 'ShowImages', false);
parse(p, basepath, extension, varargin{:});
% list directory content
dirs = dir(p.Results.basepath);
dirs(~[dirs.isdir]) = []; %remove non-directories
dir_names = { dirs.name }';
dir_names(ismember(dir_names, {'.', '..'})) = [];
% result matrices
I = [];
A = [];
%% iterate all sub-folders
for i = 1:length(dir_names)
dir_path = fullfile(basepath, dir_names{i});
files = dir(fullfile(dir_path, p.Results.extension));
file_names = { files.name }';
%% iterate files within a certain sub-folder
for j = 1:length(file_names)
file_path = fullfile(dir_path, file_names{j});
img = imread(file_path);
I = cat(3, I, img);
end
A = [A repelem(i, length(file_names))];
end
end