|
a |
|
b/functions/functions_Gabor/findBestWaveletsTesting.m |
|
|
1 |
function [bestWaveletsAll, PCANet] = findBestWaveletsTesting(imagesCell, orient_default, orient_best, PCANet, numImagesToUse, imageSize, fidLogs, param, stepPrint, plotta) |
|
|
2 |
|
|
|
3 |
%init |
|
|
4 |
bestWaveletsAll(param.numBestWavelets).filter = []; |
|
|
5 |
|
|
|
6 |
%display |
|
|
7 |
fprintf_pers(fidLogs, ['\t\t\t' num2str(numImagesToUse) ' images used for Gabor analysis... \n']) |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
%-------------------------------------- |
|
|
11 |
%Compute parametrized wavelets |
|
|
12 |
%parametrizedWavelets = gaborArrayParametrized(param.sigma, param.wavelength, param.divThetaParametrized); |
|
|
13 |
parametrizedWavelets = gaborArrayParametrized(param.sigma, param.wavelength, deg2rad(orient_default)); |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
%-------------------------------------- |
|
|
17 |
%Compute complete multi-scale Gabor filter bank |
|
|
18 |
%fprintf_pers(fidLogs, '\t\tComputing Gabor array... \n') |
|
|
19 |
gaborBank = gaborArrayFromScales(imageSize, deg2rad(unique([orient_default orient_best])), param, plotta); |
|
|
20 |
|
|
|
21 |
%init counter for how many times each wavelet is chosen |
|
|
22 |
o_counterAll = zeros(numel(gaborBank), 1); |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
if plotta |
|
|
26 |
fsfigure |
|
|
27 |
for indf = 1 : param.divThetaParametrized |
|
|
28 |
%sum(real(parametrizedWavelets(indf).filter(:))) |
|
|
29 |
subplot(1,param.divThetaParametrized,indf) |
|
|
30 |
imshow(real(parametrizedWavelets(indf).filter),[]) |
|
|
31 |
axis on |
|
|
32 |
axis image |
|
|
33 |
end %for indf |
|
|
34 |
suplabel([num2str(param.divThetaParametrized) ' filters fixed']); |
|
|
35 |
figure, |
|
|
36 |
imhist(real(parametrizedWavelets(indf).filter)) |
|
|
37 |
%pause |
|
|
38 |
end %if plotta |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
%loop on images |
|
|
43 |
parfor j = 1 : numImagesToUse |
|
|
44 |
% for j = 1 : numel(imagesCell) |
|
|
45 |
|
|
|
46 |
%get id of current worker |
|
|
47 |
t = getCurrentTask(); |
|
|
48 |
|
|
|
49 |
%display progress |
|
|
50 |
if mod(j, stepPrint) == 0 |
|
|
51 |
fprintf(1, ['\t\tCore ' num2str(t.ID) ': ' num2str(j) ' / ' num2str(numImagesToUse) '\n']) |
|
|
52 |
end %if mod(i, 100) == 0 |
|
|
53 |
|
|
|
54 |
%get img |
|
|
55 |
im = imagesCell{j}; |
|
|
56 |
|
|
|
57 |
%test img alternative |
|
|
58 |
%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
59 |
%im = loadPreprocessImage('D:\UoT\Projects\Palmprint Gabor tuning\Code\alt\GaborWavelet\images\1_1.jpg', imageSize); |
|
|
60 |
%im = loadPreprocessImage('D:\UoT\Projects\Palmprint Gabor tuning\Code\alt\GaborWavelet\images\test image\Peppers.tiff', imageSize); |
|
|
61 |
%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
%pause |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
%-------------------------------------- |
|
|
68 |
%Compute frequency of Gabor filter bank |
|
|
69 |
%fprintf_pers(fidLogs, '\t\tComputing spectrum of gabor array... \n') |
|
|
70 |
%totFreq = computeFrequencyGaborArray(gaborBank, plotta); |
|
|
71 |
|
|
|
72 |
|
|
|
73 |
%-------------------------------------- |
|
|
74 |
%Perform reference Gabor filtering |
|
|
75 |
%fprintf_pers(fidLogs, '\t\tPerforming reference Gabor filtering... \n') |
|
|
76 |
resF = referenceGaborFilter(gaborBank, im); |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
%-------------------------------------- |
|
|
80 |
%create powerMap for all filters |
|
|
81 |
%fprintf_pers(fidLogs, '\t\tComputing powermaps... \n') |
|
|
82 |
powerMapF = computePowerMaps(resF, gaborBank); |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
%-------------------------------------- |
|
|
86 |
%Sort filter response information |
|
|
87 |
%fprintf_pers(fidLogs, '\t\tSorting filter response information... \n') |
|
|
88 |
[sortRes, sizeRes] = sortFilterResponse(gaborBank, powerMapF); |
|
|
89 |
|
|
|
90 |
|
|
|
91 |
%-------------------------------------- |
|
|
92 |
%Compute most used wavelets |
|
|
93 |
%fprintf_pers(fidLogs, '\t\t\tComputing most used wavelets... \n') |
|
|
94 |
o_counter = getMostUsedWavelets(sortRes, gaborBank, powerMapF, param, sizeRes, plotta); |
|
|
95 |
|
|
|
96 |
%increment |
|
|
97 |
o_counterAll = o_counterAll + o_counter; |
|
|
98 |
|
|
|
99 |
end %for j = 1 : length(vectorIndexTest) |
|
|
100 |
|
|
|
101 |
|
|
|
102 |
%display most used filters |
|
|
103 |
if plotta |
|
|
104 |
figure, |
|
|
105 |
bar(1:size(o_counterAll), o_counterAll) |
|
|
106 |
xlabel('Wavelet n.') |
|
|
107 |
ylabel('Perc. of occurence') |
|
|
108 |
title('Most used wavelets'); |
|
|
109 |
end %if plotta |
|
|
110 |
|
|
|
111 |
|
|
|
112 |
%-------------------------------------- |
|
|
113 |
%sort most used filters counter |
|
|
114 |
[~, ind_o_counter_All_sort] = sort(o_counterAll, 'descend'); |
|
|
115 |
|
|
|
116 |
%consider only best wavelets |
|
|
117 |
ind_o_counter_All_sort = ind_o_counter_All_sort(1 : param.numBestWavelets); |
|
|
118 |
bestWavelets = gaborBank(ind_o_counter_All_sort); |
|
|
119 |
|
|
|
120 |
%display bestWavelets |
|
|
121 |
if plotta |
|
|
122 |
fsfigure |
|
|
123 |
for indf = 1 : numel(bestWavelets) |
|
|
124 |
subplot(1, numel(bestWavelets),indf) |
|
|
125 |
imshow(bestWavelets(indf).even,[]) |
|
|
126 |
axis on |
|
|
127 |
axis image |
|
|
128 |
end %for indf |
|
|
129 |
suplabel([num2str(numel(bestWavelets)) ' filters most used']); |
|
|
130 |
end %if plotta |
|
|
131 |
|
|
|
132 |
|
|
|
133 |
%-------------------------------------- |
|
|
134 |
%assign to global structure |
|
|
135 |
countfilter = 1; |
|
|
136 |
|
|
|
137 |
%parametrized |
|
|
138 |
for o = 1 : numel(parametrizedWavelets) |
|
|
139 |
bestWaveletsAll(countfilter).filter = parametrizedWavelets(o).filter; |
|
|
140 |
countfilter = countfilter + 1; |
|
|
141 |
end %for o |
|
|
142 |
|
|
|
143 |
%dynamic |
|
|
144 |
for o = 1 : numel(bestWavelets) |
|
|
145 |
bestWaveletsAll(countfilter).filter = complex(bestWavelets(o).even, bestWavelets(o).odd); |
|
|
146 |
countfilter = countfilter + 1; |
|
|
147 |
end %for o |
|
|
148 |
|
|
|
149 |
%display |
|
|
150 |
% if plotta |
|
|
151 |
% bestWaveletsCell = squeeze(struct2cell(bestWavelets)); |
|
|
152 |
% figure, |
|
|
153 |
% subplot(1,2,1) |
|
|
154 |
% montage(bestWaveletsCell(1,:), 'DisplayRange', []) |
|
|
155 |
% axis on |
|
|
156 |
% axis image |
|
|
157 |
% title('Best wavelets: even'); |
|
|
158 |
% subplot(1,2,2) |
|
|
159 |
% montage(bestWaveletsCell(2,:), 'DisplayRange', []) |
|
|
160 |
% title('Best wavelets: odd'); |
|
|
161 |
% pause |
|
|
162 |
% end %if plotta |
|
|
163 |
|
|
|
164 |
|
|
|
165 |
%-------------------------------------- |
|
|
166 |
%loop on images, test reconstruct |
|
|
167 |
if 0 |
|
|
168 |
for j = 1 : numel(imagesCell) |
|
|
169 |
|
|
|
170 |
%get img |
|
|
171 |
im = imagesCell{j}; |
|
|
172 |
%Perform reference Gabor filtering |
|
|
173 |
resF = referenceGaborFilter(bestWaveletsAll, im); |
|
|
174 |
%create powerMap for all filters |
|
|
175 |
powerMapF = computePowerMaps(resF, bestWaveletsAll); |
|
|
176 |
%Sort filter response information |
|
|
177 |
[sortRes, sizeRes] = sortFilterResponse(bestWaveletsAll, powerMapF); |
|
|
178 |
|
|
|
179 |
%-------------------------------------- |
|
|
180 |
%Loop on wavelets - all filters |
|
|
181 |
%fprintf_pers(fidLogs, '\t\t\tReconstructing image with all filters... \n') |
|
|
182 |
% allFiltersIndexes = 1:numel(gaborBank); |
|
|
183 |
%[tmpImage, errV] = reconstructImage(resF, sortRes, gaborBank, powerMapF, allFiltersIndexes, im, imageSize, sizeRes, param, plotta); |
|
|
184 |
|
|
|
185 |
|
|
|
186 |
%-------------------------------------- |
|
|
187 |
%Loop on wavelets - best filters |
|
|
188 |
%fprintf_pers(fidLogs, ['\t\t\tReconstructing image with the best ' num2str(param.numBestWavelets) ' filters... \n']) |
|
|
189 |
[tmpImageBest, errBestV] = reconstructImage(resF, sortRes, bestWaveletsAll, powerMapF, [1 : numel(bestWaveletsAll)], im, imageSize, sizeRes, param, plotta); |
|
|
190 |
|
|
|
191 |
pause |
|
|
192 |
|
|
|
193 |
end %for j = 1 : numel(imagesCell) |
|
|
194 |
end %if 0 |
|
|
195 |
|
|
|
196 |
|
|
|
197 |
%-------------------------------------- |
|
|
198 |
%update number of filters |
|
|
199 |
%assign updated number of filters to PCANet |
|
|
200 |
PCANet.NumFilters(end) = numel(bestWaveletsAll); |
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|