32
32
% validy.mat, validx.txt and validy.txt. The text files are meant to store the result in a
33
33
% format which can be accessed by other programs also in the future.
35
% Changed by Suren A. Chilingaryan <csa@dside.dyndns.org> to optimize performance
36
% by tighter integration with Matlab images toolkit (few sources from the toolkit
37
% are moved to the current source tree and adjusted to benefit from knowledge of
38
% tasks we are solving here. As well CUDA framework, if available, is used to
39
% speed-up core computations using parallel processors of latest NVidia video
41
% OPTIMIZE parameter is controlling which optimizations should be used.
42
% 0 - The original version, no optimizations
43
% 1 - The modified sources from images toolkit are used
44
% 2 - The CUDA matlab plugin is used to compute FFT's
45
% 3 - Most of computations are performed on NVidia card
46
% You can safely set an optimization level to 3. If NVidia card is not available
47
% the level will be automatically reduced to 1.
41
57
% exist('filenamelist')
143
%moved from normxcorr2
144
% We can precalculate it here, since near-edge images are dropped and, therefore, A,T always have the same size
145
% n is width and height of T, but following computations are done for A
146
% outsize is sum if widths and heights of T and A - 1 (outsize = size(A) + size(T) - 1)
147
outsize = 6 * CORRSIZE + 1;
128
151
rects_base = dic_calc_rects(base_points_for,2*CORRSIZE,base);
131
154
data_base = struct;
135
156
ncp = size(base_points_for, 1);
137
hwid = normxcorr_hw();
138
normxcorr_hw(hwid, 1, ncp, CORRSIZE);
159
hwid = normxcorr_hw();
161
normxcorr_hw(hwid, 1, ncp, CORRSIZE);
141
175
if isequal(rects_base(icp,3:4),[0 0])
143
177
data_base(icp).skip = 1;
159
193
error(eid,'%s',msg);
162
%moved from normxcorr2
163
% We can precalculate it here, since near-edge images are dropped and, therefore, A,T always have the same size
164
% n is width and height of T, but following computations are done for A
168
196
double_sub_base = double(sub_base);
169
197
local_sum_A = dic_local_sum(double_sub_base,n,n);
170
198
local_sum_A2 = dic_local_sum(double_sub_base.*double_sub_base,n,n);
173
200
% Note: diff_local_sums should be nonnegative, but may have negative
174
201
% values due to round off errors. Below, we use max to ensure the
175
202
% radicand is nonnegative.
176
203
denom_A = sqrt( max(( local_sum_A2 - (local_sum_A.^2)/mn ) / (mn-1), 0) );
177
204
i_nonzero = find(denom_A~=0);
180
% data_base(icp).denom_A = denom_A;
181
% data_base(icp).i_nonzero = i_nonzero;
183
% data_base(icp).local_sum_A = local_sum_A;
184
% data_base(icp).sub_base = sub_base;
187
206
data_base(icp).skip = 0;
189
normxcorr_hw(hwid, 10, icp, sub_base, single(local_sum_A), single(denom_A), uint16(i_nonzero));
209
normxcorr_hw(hwid, 10, icp, sub_base, single(local_sum_A), single(denom_A), uint16(i_nonzero));
211
data_base(icp).denom_A = denom_A;
212
data_base(icp).i_nonzero = i_nonzero;
214
data_base(icp).local_sum_A = local_sum_A;
215
data_base(icp).sub_base = sub_base;
218
data_base(icp).sub_base_fft = fft2_cuda(double_sub_base, outsize, outsize);
220
data_base(icp).sub_base_fft = fft2(double_sub_base, outsize, outsize);
191
224
data_base(icp).base_fractional_offset = base_points_for(icp,:) - round(base_points_for(icp,:)*PRECISION)/PRECISION;
228
normxcorr_hw(hwid, 2);
195
232
%normxcorr_hw(hwid);
198
normxcorr_hw(hwid, 2);
200
236
for i=firstimage:(r-1) % run through all images
201
237
tic % start the timer
205
241
input_points_for(:,1)=reshape(input_points_x,[],1); % we reshape the input points to one row of values since this is the shape cpcorr will accept
206
242
input_points_for(:,2)=reshape(input_points_y,[],1);
208
input_correl(:,:)=dic_cpcorr(CORRSIZE, PRECISION, hwid, data_base, input_points_for, input); % here we go and give all the markers and images to process to cpcorr.m which ic a function provided by the matlab image processing toolbox
245
input_correl(:,:)=dic_cpcorr(CORRSIZE, PRECISION, OPTIMIZE, hwid, data_base, input_points_for, input); % here we go and give all the markers and images to process to cpcorr.m which ic a function provided by the matlab image processing toolbox
247
input_correl(:,:)=cpcorr(input_points_for, base_points_for, input, base);
209
249
input_correl_x=input_correl(:,1); % the results we get from cpcorr for the x-direction
210
250
input_correl_y=input_correl(:,2); % the results we get from cpcorr for the y-direction