-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathloadImages.m
70 lines (55 loc) · 1.71 KB
/
loadImages.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
function [imData, txtData, imDims] = loadImages(directory, sz, preserveAR, checkForText, filterTextRegions)
txtData = [];
nX = sz(1);
nY = sz(2);
nC = sz(3);
filenames = getAllFiles(directory);
if (checkForText)
textFilenames = getAllFiles(fullfile(directory,'\text\'));
nText = length(textFilenames);
haveTxt = zeros(nText,1);
for i=1:nText
haveTxt(i) = filenameToIndex(textFilenames{i});
end
filteredFilenames = [];
for i=1:length(filenames)
if (any(filenameToIndex(filenames{i}) == haveTxt))
filteredFilenames = [filteredFilenames; filenames(i)];
end
end
filenames = filteredFilenames;
txtData = TextFeatureSet.empty(nText,0);
for i = 1:length(filenames)
txtData(i) = TextFeatureSet(textFilenames{i});
end
end
imData = zeros(length(filenames),nX*nY*nC);
imDims = zeros(length(filenames),2);
for i = 1:length(filenames)
I = imread(filenames{i});
if (length(size(I)) == 3)
I = rgb2gray(I);
end
imDims(i,:) = size(I);
if (filterTextRegions)
I = txtData(i).filterOutTextAreasSmooth(I);
end
if preserveAR
I = imresize_constantAR(I,[nX nY]);
else
I = imresize(I, [nX nY]);
end
imData(i,:) = reshape(I,[1,nX*nY*nC]);
end
% meanDim = mean(imDims,1);
% disp(meanDim);
end
function fileList = getAllFiles(dirName)
dirData = dir(dirName); %# Get the data for the current directory
dirIndex = [dirData.isdir]; %# Find the index for directories
fileList = {dirData(~dirIndex).name}'; %'# Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
end
end