-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrafischeAuswertung.m
279 lines (213 loc) · 10.1 KB
/
GrafischeAuswertung.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
function [ ] = GrafischeAuswertung()
% Creates a lot of graphics in a specified folder
% Changelog: -
tic
%% PARAMETERS:
structextension = '.mat';
file = 'S';%filename of the struct containing the values (e.g. S.mat)
feature_one = 'Haralick'; %string to look for in file
feature_two = 'Laws';
feature_three = 'LBP';
haralicks = {'Haralick0'; 'Haralick45'; 'Haralick135';'Haralick90'};
%% Change the current folder to the folder of this m-file
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
%% Process 'Samples'
mainFolder = '../Samples/';
r = dir(mainFolder);
%% Receive the content of the features stored in S
fprintf('Receiving feature content...\n');
for l=1:length(r)
if (r(l).isdir)
if (r(l).name ~= '.')
folder = strcat(mainFolder, r(l).name, '/');
%for each S.mat
% values = all sub values from a given searchstring within the file
% Haralicks
values_one = Cl_GetClusterContent(folder, file, structextension, feature_one);
% Laws
values_two = Cl_GetClusterContent(folder, file, structextension, feature_two);
% LBP
values_three = Cl_GetClusterContent(folder, file, structextension, feature_three);
break;
end
end
end
%% content is now is stored in: values_one, values_two
%Laws
ProcessData(Cl_GetClusterContent(folder, file, structextension, feature_two), 'Laws');
%Haralick
ProcessData(Cl_GetClusterContent(folder, file, structextension, feature_one), 'Haralick');
%Rotation invariant Histogram
ProcessData(Cl_GetClusterContent(folder, file, structextension, feature_three), 'LBP26');
return; %from main
function ProcessData(values, textureFeature)
%iterate through all value pairs in all folders
mainFolder = '../Samples/';
r = dir(mainFolder);
structextension = '.mat';
file = 'S';%filename of the struct containing the values (e.g. S.mat)
for i=1:length(values)
current ='';
s={};
fprintf('\n--------------Processing feature %s, %i/%i --------------\n' ,char(values(i)), i,length(values) );
%and do this for each folder
for l=1:length(r)
if (r(l).isdir)
if (r(l).name ~= '.')
folder = strcat(mainFolder, r(l).name, '/'); %current folder e.g. [../Samples/Blatt_mit/]
tmp = r(l).name; % folder name e.g. [Blatt_180]
str = regexp(tmp,'\_','split');%split string, to get something like 'Blatt' '180'
%if current is still empty; current keeps track of the
%current picture
%needed for comparism against the following picture and
%whether to start a new image or not
if (strcmp('',current) == 1)
current = str(1);%if it is the first, remember current will be reset after each iteration
end
%Get current data
if(findstr(textureFeature, 'LBP')==1)
if(i>1) %for LBP don't go in there for more than once
break;
end
val = Cl_GetClusterData(folder, file, 'LBP' , textureFeature, structextension); % extract data
%%Gather all values from all sub pictures in s
if isempty(s) %if the struct is empty, put in the first values
s = struct(str{2}, {val(1).values});
%otherwise create new struct and concat both
else
c = struct(str{2}, {val(1).values}); % new struct
fn1 = fieldnames(s);%old fieldnames
c1 = struct2cell(s);%convert to cell array
fn2 = fieldnames(c);%new (additional) fieldnames
c2 = struct2cell(c);%also convert the other struct
fn = [fn1;fn2]; %merge the fieldnames
cc = [c1;c2]; %and merge the cell arrays
%to finally put together everything in the new struct
s = cell2struct(cc, fn,1);
% so s will be in the end something like:
% s =
% AutoTone: [1x26 double]
% Exposure: [1x26 double]
end
%% Check if the next image is still in the same category...
if (l+1) <= length(r) %but only if there is a next picture
next = r(l+1).name;
end
str2 = regexp(next,'\_','split');
if (strcmp(str2(1),current) == 0) %start creating a figure if a new picture is waiting in line
CreateHistogram(str(1), textureFeature, s);
%% Finally clear everything for the next category of samples
current = ''; %set current again to nothing, 'cause the next one is coming
s=struct(); %and the struct is empty again
end
else
val = Cl_GetClusterData(folder, file, textureFeature, values(i) , structextension); % extract data
%%Gather all values from all sub pictures in s
if isempty(s) %if the struct is empty, put in the first values
s = struct(str{2}, {val.values});
%otherwise create new struct and concat both
else
c = struct(str{2}, {val.values}); % new struct
fn1 = fieldnames(s);%old fieldnames
c1 = struct2cell(s);%convert to cell array
fn2 = fieldnames(c);%new (additional) fieldnames
c2 = struct2cell(c);%also convert the other struct
fn = [fn1;fn2]; %merge the fieldnames
cc = [c1;c2]; %and merge the cell arrays
%to finally put together everything in the new struct
s = cell2struct(cc, fn,1);
% so s will be in the end something like:
% s:
% mit: [4x2 double]
% ohne: [4x2 double]
% weich: [4x2 double]
end
%% Check if the next image is still in the same category...
if (l+1) <= length(r) %but only if there is a next picture
next = r(l+1).name;
end
str2 = regexp(next,'\_','split');
if (strcmp(str2(1),current) == 0) %start creating a figure if a new picture is waiting in line
fprintf('Processed: %s \n' ,char(str(1))); % Show which picture is being processed
%...if not, reset everyting
CreateFigure(s,current,values(i), textureFeature);
%% Finally clear everything for the next category of samples
current = ''; %set current again to nothing, 'cause the next one is coming
s=struct(); %and the struct is empty again
end
end
end
end
end
end
return;
function CreateHistogram(s1, textureFeature, val)
% visualize the histogram
% figure, bar(1:binNum26, hst26, 'r'), title('26bins LBP hist');
colors = ['y' 'm' 'c' 'r' 'g' 'b' 'k' 'w']; %set up a range of colors
%create plot
scrsz = get(0,'ScreenSize');
h = figure('Position',[1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2]);
%size
ll = length(fieldnames(val)); % e.g. ll = 8
%structure
fn = fieldnames(val);
%for each entry
for j=1:ll
subplot(ceil(ll/2),2,j)
b = getfield(val, char(fn(j)));
bar(1:length(b), b, colors(j));
tit = strcat(s1, '.', char(fn(j)));
title(tit, 'fontsize',15,'fontweight','b');
end
%Set style and title
fname = strcat('../Output/',s1,'_', textureFeature, '.jpg');
%save
saveas(h, char(fname), 'jpg');
close(h); %close the image
return
function CreateFigure(s,current,current_value, y)
colors = ['y' 'm' 'c' 'r' 'g' 'b' 'k' 'w']; %set up a range of colors
%% Create figure/ plot
%preprocessing
fieldnms = fieldnames(s);
xaxis = [1/4 1/2 2/3 1];%x axis containing the pictures (full, half, quarter size)
%create plot
scrsz = get(0,'ScreenSize');
h = figure('Position',[1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2]);
for j=1:length(fieldnms)
v = getfield(s, fieldnms{j});%mit, ohne, weich,..
val = v(:,1); %first column, containing 4 values for 4 pictures
linestyle = '--';%can be also '' to avoid lines
col = strcat(linestyle, colors(j), 's'); % s=squares
plot(xaxis,flipud(val),... %flip the vector, so the full size image value is in at end
char(col), 'MarkerSize' , 10,... % convert character array to string [char(col)]
'MarkerFaceColor', char(colors(j)));
hold on
end
%Adjust the xaxis
set(gca, 'XTick',[0.25 0.5 0.66 1])
set(gca, 'XTickLabel',{'25%','50%','66%','100%'})
set(gca,'Color',[0.9,0.9,0.9])
%Legend
hleg = legend(fieldnms, 'Location', 'NorthEast');
set(hleg,'FontAngle','italic')
%Set style and title
title(current, 'fontsize',20,'fontweight','b');
%Background
%TODO
yl = strcat(y ,'(', ' ' ,current_value, ')');
ylabel(yl, 'fontsize',12,'fontweight','b');
xlabel('Image size','fontsize',12,'fontweight','b');
grid on;
hold off
%%Save image
%create a filename: e.g. SAMPLE_FEATURE/SUBFEATURE.jpg
fname = strcat('../Output/',current,'_', yl, '.jpg');
%save
saveas(h, char(fname), 'jpg');
close(h); %close the image
return;
toc