-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuningCurveScript.m
182 lines (146 loc) · 5.25 KB
/
tuningCurveScript.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
parameters
%% Construct db of training descriptors
[d_db,kp_db] = getDescriptorDB(db_path,RESIZE_FACTOR,method);
%%
[d_q,kp_q] = getDescriptorDB(query_path,RESIZE_FACTOR,method);
filename = [datestr(date,'yyyymmdd'),method,corridor];
save(filename,'d_db','kp_db','d_q','kp_q');
%%
N_q = length(d_q);
wb = waitbar(0,'Generating the metric...');
for ix = 1:N_q
for ii = 1:length(d_db) % featureDatabase is a GLOBAL VARIABLE from the database. for each training image
[matches, scores] = vl_ubcmatch(d_q{ix},d_db{ii}); % match each test image(k) to each training image(i)
% if (length(scores) > 10) % if matched SIFT keypoints are greater than 10
scoreStruct(ii) = struct('distance',scores, 'index', matches); % store the training image product id and distance of test and training image keypoints in a structure
dist (ii) = mean(scores); % calculate the average of the descriptor euclidean distance
% else
% scoreStruct(ii) = struct('distance',NaN, 'index', NaN);
% dist (ii) = NaN; % else discard that training image as a possible match
% end
end
[minDist(ix), minIndex(ix)] = min(dist); % find the TRAINING image whose descriptor
... has minimum distance from the training
... image descriptor
distancesCell{ix} = dist;
waitbar(ix/N_q);
end % end for
distances = cat(1,distancesCell{:});
% Normalise the distances
% d' = (-d+dmax)/dmax
M = max(max(distances));
correlations = (-distances+M)/M;
distances(isnan(distances)) = M;
close(wb);
%% PLOT normalised Distances
figure('Renderer','zbuffer')
plot(correlations(1,:),'.');
axis tight
set(gca,'NextPlot','replaceChildren');
% Preallocate the struct array for the struct returned by getframe
F(size(correlations,1)) = struct('cdata',[],'colormap',[]);
% Record the movie
for j = 1:size(correlations,1)
%plot(smooth(D(j,:)));
plot(correlations(j,:),'.');
hold on;
[maxVal,idxmax] = max(correlations(j,:));
% plot(idxmax,maxVal,'rs','LineWidth',2,'MarkerFaceColor','g','MarkerSize',10);
F(j) = getframe;
hold off;
end
[h, w, p] = size(F(1).cdata);
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf,'Position', [150 150 w h]);
axis off
% Place frames at bottom left
movie(hf,F,1,2,[0 0 0 0]);
%% PLOT distances
figure('Renderer','zbuffer')
plot(distances(1,:));
axis tight
set(gca,'NextPlot','replaceChildren');
% Preallocate the struct array for the struct returned by getframe
F(size(distances,1)) = struct('cdata',[],'colormap',[]);
% Record the movie
for j = 1:size(distances,1)
% plot(smooth(D(j,:)));
plot(distances(j,:));
hold on;
% [maxVal,idxmax] = max(Dplots(j,:));
% plot(idxmax,maxVal,'rs','LineWidth',2,'MarkerFaceColor','g','MarkerSize',10);
F(j) = getframe;
hold off;
end
[h, w, p] = size(F(1).cdata);
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf,'Position', [150 150 w h]);
axis off
% Place frames at bottom left
movie(hf,F,4,5,[0 0 0 0]);
%% XCORR results
windowLength = 400;
%%
figure('Renderer','zbuffer')
plot(distances(1,:));
axis tight
set(gca,'NextPlot','replaceChildren');
% Preallocate the struct array for the struct returned by getframe
F(size(distances,1)) = struct('cdata',[],'colormap',[]);
H = hamming(windowLength);
% Record the movie
for j = 1:size(distances,1)
% Y = xcorr(H,distances(j,:));
Y = normxcorr1(H',distances(j,:));
plot(Y);
hold on;
[maxVal,idxmax] = max(Y);
plot(idxmax,maxVal,'rs','LineWidth',2,'MarkerFaceColor','g','MarkerSize',10);
F(j) = getframe;
hold off;
end
[h, w, p] = size(F(1).cdata);
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf,'Position', [150 150 w h]);
axis off
% Place frames at bottom left
movie(hf,F,20,1,[0 0 0 0]);
%% A moving average case
windowSize = 20;
b = ones(1,windowSize)/windowSize;
a= 1;
span = 20;
figure('Renderer','zbuffer')
plot(correlations(1,:));
axis([1 size(distances,1) 0 1])
set(gca,'NextPlot','replaceChildren');
% Preallocate the struct array for the struct returned by getframe
F(size(distances,1)) = struct('cdata',[],'colormap',[]);
% Record the movie
averagedSignal = zeros(size(distances));
for j = 1:size(distances,1)
%plot(smooth(D(j,:)));
averagedSignal(j,:) = filter(b,a,correlations(j,:));
plot(averagedSignal(j,:));
hold on;
[maxValAV,idxmaxAV] = max(averagedSignal(j,:));
plot(idxmaxAV,maxValAV,'rs','LineWidth',2,'MarkerFaceColor','g','MarkerSize',10);
if((idxmaxAV+span<=length(averagedSignal(j,:)))&&(idxmaxAV-span)<1)
xaxisRed = idxmaxAV-span:idxmaxAV+span;
plot(xaxisRed,averagedSignal(j,xaxisRed),'r');
end
axis([1 size(distances,2) 0 1])
F(j) = getframe;
hold off;
end
%
% [h, w, p] = size(F(1).cdata);
% hf = figure;
% % resize figure based on frame's w x h, and place at (150, 150)
% set(hf,'Position', [150 150 w h]);
% axis off
% % Place frames at bottom left
% movie(hf,F,1,2,[0 0 0 0]);