-
Notifications
You must be signed in to change notification settings - Fork 8
/
createDataset.m
executable file
·40 lines (35 loc) · 1.08 KB
/
createDataset.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
function dataset = createDataset(datasetPath, datasetName, outputMatFile)
% Image Database Creation
% Date : 2012/02/11
% Author: Ashok Kumar Pant
% Institute of Science and Technology, Computer Science, Tribhuvan
% University, Nepal
% Load images into matlab database
fileFolder = fullfile(datasetPath);
dirs = dir(fileFolder);
data = [];
iClass=1;
labels=containers.Map('KeyType','int32','ValueType','char');
for i=3:numel(dirs)
if (dirs(i).isdir==1)
dirOutput = dir(fullfile(fileFolder,dirs(i).name,'*.jpg'));
fileNames = {dirOutput.name}';
for j=1:numel(fileNames)
x=imread(fullfile(fileFolder,dirs(i).name,fileNames{j}));
datum.image = x;
datum.class=iClass;
data = [data; datum];
end
labels(iClass) = dirs(i).name;
iClass=iClass+1;
end
end
if exist('datasetName','var')
dataset.name=datasetName;
end
dataset.numClasses=iClass-1;
dataset.data=data;
dataset.labels = labels;
if exist('outputMatFile','var')
save(outputMatFile,'dataset');
end