-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathReadMatrixPartition.m
192 lines (177 loc) · 5.85 KB
/
ReadMatrixPartition.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
function [ A Class Test] = ReadMatrixPartition(TrainSize, ReadMode, Partial)
%ReadMode = 'Corruption';
if nargin < 3,
%OptTol = 1e-5;
Partial = 'RightEye';
end
global TestImageSize;
if(strcmp(ReadMode,'Disguise') == 1 )
[A Class Test] = ReadDisguisePartition(TrainSize);
return;
elseif(strcmp(ReadMode,'EYBCorrupt') == 1 )
[A Class Test] = ReadCorruption(TrainSize);
return;
end
end
function [ A Class Test] = ReadDisguisePartition(TrainSize)
global TestImageSize;
ImagePath = '.\Images\AR\';
FileListFileName = 'file.lst';
ReducingMode = 'DownSample';
A = PartitionDict;
Class = 0;
Test = 0;
OriDimension = 19800;
RandomProject = 0;
nTotalSubset = 100;
%nScale = 4;
if (ReducingMode == 'RandomFace')
RD = TestImageSize(1) * TestImageSize(2);%2016;%8064
RandomProject = zeros(RD, OriDimension); %d X m m = 32256;
for i = 1:RD
RandomProject(i,:) = normrnd(0,1, 1, OriDimension);
RandomProject(i,:) = RandomProject(i,:)./norm(RandomProject(i,:));
%RandomProject(i,:) = (RandomProject(i,:)-min(RandomProject(i,:)))./(max(RandomProject(i,:))-min(RandomProject(i,:))) ;
end
elseif (ReducingMode == 'DownSample')
end
Class = zeros(1, nTotalSubset);
for i = 1:nTotalSubset
disp(sprintf('Reading subset %d', i));
FileList = ReadSubsets (i, 'Disguise');
if(~iscell(FileList) | FileList{1}==0)
A = 0;
return;
end
Class(1, i) = size(FileList,2) - TrainSize;
%RandomList = randperm(size(FileList,2));
for j = 1:size(FileList,2)
File = FileList{j};
%disp(File);
%File = strcat(File, FileList{j});
[tmp0, map] = imread(File);
tmp0 = rgb2gray(tmp0);
%[coefs, sizes] = MyDWT(tmp1);
%tmp1 = VisualizeDWT(coefs, sizes, sizes(size(sizes, 1),:));
%tmp1 = imresize(tmp1, fix(size(tmp1)/nScale));
tmp0 = imresize(tmp0, TestImageSize);
tmp1(:,:) = cast(tmp0(:,:), 'double');
tmp1(:,:) = tmp1(:,:)./255;
%if(j<=size(FileList,2) - TestSize)
if(j<=TrainSize)
%partition
A = A.AddElement(tmp1);
else
if Test == 0
Test = tmp1(:);
else Test(:, end+1) = tmp1(:);
end
end
clear tmp;
end
end
end
function [ A Class Test] = ReadCorruption(TrainSize)
global TestImageSize;
global ImagePath;
%ImagePath = '.\Images\EYB\';
TrainFileName = 'Subset12.txt';
TestFileName = 'Subset3.txt';
ReducingMode = 'DownSample';
A = PartitionDict;
Class = 0;
Test = 0;
DirListFileName = 'dir.lst';
DirList = ReadList(DirListFileName);
if(~iscell(DirList) | DirList{1}==0)
A = 0;
return;
end
OriDimension = 32256;
RandomProject = 0;
%nScale = 4;
Class = zeros(1, size(DirList,2));
for i = 1:size(DirList,2)
Dir = strcat(ImagePath, DirList{i});
disp(Dir);
FileList1 = ReadList(sprintf('%s\\%s', Dir,TrainFileName));
if(~iscell(FileList1) | FileList1{1}==0)
A = 0;
return;
end
FileList2 = ReadList(sprintf('%s\\%s', Dir,TestFileName));
if(~iscell(FileList2) | FileList2{1}==0)
A = 0;
return;
end
%Class(1, i) = size(FileList,2) - TestSize;
Class(1, i) = size(FileList2,2);
%RandomList = randperm(size(FileList,2));
for k = 1:2
if(k==1)
FileList = FileList1;
else FileList = FileList2;
end
for j = 1:size(FileList,2)
if(k==1 & j>TrainSize)
continue;
end
File = strcat( Dir, '\');
%File = strcat(File, FileList{RandomList(j)});
%disp(File);
File = strcat(File, FileList{j});
%tmp1 = imread(File);
tmp0 = imread(File);
tmp0 = imresize(tmp0, TestImageSize);
tmp1(:,:) = cast(tmp0(:,:), 'double');
tmp1(:,:) = tmp1(:,:)./255;
if(k==1)
A = A.AddElement(tmp1);
else
if Test == 0
Test = tmp1(:);
else Test(:, end+1) = tmp1(:);
end
end
clear tmp;
end
end
end
end
function [List] = ReadSubsets (nSubset, Feature)
if(nSubset<10)
FileName = sprintf('Subset00%d.lst', nSubset);
elseif(nSubset<100)
FileName = sprintf('Subset0%d.lst', nSubset);
else
FileName = sprintf('Subset%d.lst', nSubset);
end
FileList = ReadList(FileName);
if(~iscell(FileList) | FileList{1}==0)
List = 0;
return;
end
%Class(1, i) = size(FileList,2) - TrainSize;
%RandomList = randperm(size(FileList,2));
List = '';
if(strcmp(Feature,'Normal') == 1)
for j = 1:size(FileList,2)
if(j < 8 | (j>13 & j<21))
List{end+1} = FileList{j};
end
end
end
if(strcmp(Feature,'Disguise') == 1)
for j = 1:size(FileList,2)
if(j < 5 | (j>13 & j<18))
List{end+1} = FileList{j};
end
end
%sun glass
List{end+1} = FileList{8};
List{end+1} = FileList{21};
%scarf
List{end+1} = FileList{11};
List{end+1} = FileList{24};
end
end