-
Notifications
You must be signed in to change notification settings - Fork 67
/
ncorr_alg_seedanalysis.m
129 lines (115 loc) · 6.81 KB
/
ncorr_alg_seedanalysis.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
function [seedinfo,convergence,outstate] = ncorr_alg_seedanalysis(reference,current,roi,num_region,pos_seed,radius,cutoff_diffnorm,cutoff_iteration,enabled_stepanalysis,subsettrunc,num_img,total_imgs)
% This function attempts to calculate seeds for the region specified.
%
% Inputs -----------------------------------------------------------------%
% reference - ncorr_class_img; used for calculations.
% current - ncorr_class_img; used for calculations.
% roi - ncorr_class_roi; ROI corresponding to the reference image.
% num_region - integer; number corresponding to the region.
% pos_seed - integer array; 1st column is the x-position of the seed; 2nd
% is the y-position. Each row corresponds to a thread in ascending order
% (i.e. the first row is the first thread).
% radius - integer; radius of subset
% cutoff_diffnorm - double; cutoff of norm of the difference vector
% cutoff_iteration - integer; cutoff for number of iterations
% enabled_stepanalysis - logical; if true, then process as many seeds as
% possible. If false, process all the seeds.
% subsettrunc - logical; if true, then enabled subset truncation
% num_img - integer; number of reference image being analyzed
% total_imgs - integer; total number of images being analyzed
%
% Outputs ----------------------------------------------------------------%
% seedinfo - struct; contains
% struct('paramvector',{},'num_region',{},'num_thread',{},'computepoints',{})
% convergence - struct; contains
% struct('num_iterations',{},'diffnorm',{})
% outstate - integer; returns either out.cancelled, out.failed, or
% out.success.
%
% Note that if step analysis is enabled, this function will return at least
% one seed if outstate is set to success. If step analysis is disabled then
% all images will be seeded if outstate is set to success.
% Initialze outputs
outstate = out.cancelled;
seedinfo = struct('paramvector',{},'num_region',{},'num_thread',{},'computepoints',{}); % Contains seed information for the RG-DIC analysis
convergence = struct('num_iterations',{},'diffnorm',{}); % Contains convergence info
% Prepare buffers
seedinfo_prelim = struct('paramvector',{},'num_region',{},'num_thread',{},'computepoints',{}); % Contains seed information for the RG-DIC analysis
convergence_prelim = struct('num_iterations',{},'diffnorm',{}); % Contains convergence info
% Set up waitbar
h = waitbar((num_img)/total_imgs,['Processing seed(s) for image ' num2str(num_img+1) ' of ' num2str(total_imgs) '...'],'Name','Calculating...','WindowStyle','modal');
set(h,'CloseRequestFcn','setappdata(gcbf,''canceling'',1)');
setappdata(h,'canceling',0);
% Iterate over current images and place seeds
tic
for i = 0:length(current)-1
% Calculate seeds for this image and region. Note that for
% ncorr_alg_calcseeds, outstate will either return success if all
% seeds are successfully calculated for this image/region, or it
% will return failed.
[seedinfo_buffer,convergence_buffer,outstate_seeds] = ncorr_alg_calcseeds(reference.formatted(), ...
current(i+1).formatted(), ...
roi.formatted(), ...
int32(num_region), ...
int32(pos_seed), ...
int32(radius), ...
cutoff_diffnorm, ...
int32(cutoff_iteration), ...
logical(enabled_stepanalysis), ...
logical(subsettrunc));
if (enabled_stepanalysis)
% If seed placement fails or if the diffnorm or corrcoef for any
% of the seeds in this image and region are greater than the
% absolute cutoff or if this is the 2nd+ image and the number
% of iterations is saturated for any of the seeds, then break.
% Choose the 2nd image because if the number of iterations is
% saturated, that doesnt necessarily mean its analyzed
% incorrectly, but it means that the match is probably poor.
% Set absolute cutoff for diffnorm and corrcoef
cutoff_max_diffnorm = 0.1;
cutoff_max_corrcoef = 0.5;
corrcoef_buffer = vertcat(seedinfo_buffer.paramvector);
corrcoef_buffer = corrcoef_buffer(:,9);
if (outstate_seeds ~= out.success || ...
any([convergence_buffer.diffnorm] > cutoff_max_diffnorm) || ...
any(corrcoef_buffer > cutoff_max_corrcoef) || ...
(i > 0 && any([convergence_buffer.num_iterations] == cutoff_iteration)))
% Check if the number of seeds is zero for step analysis;
% if so, then fail the analysis
if (isempty(seedinfo_prelim))
outstate = out.failed;
end
break;
end
else
% Step analysis isn't enabled. If any seed placements fail then
% fail the whole analysis
if (outstate_seeds ~= out.success)
h_error = errordlg('Some seeds could not be analyzed. If high strain is anticipated, then try enabling the high strain step analysis.','Error','modal');
uiwait(h_error);
outstate = out.failed;
break;
end
end
% Append seeds
seedinfo_prelim(:,1,i+1) = seedinfo_buffer;
convergence_prelim(:,1,i+1) = convergence_buffer;
% See if analysis was cancelled by user
if (getappdata(h,'canceling'))
delete(h);
% Exit
return;
end
% Update waitbar
waitbar((num_img+i+1)/total_imgs,h,['Processing seed(s) for image ' num2str(num_img+i+1) ' of ' num2str(total_imgs) '...']);
end
toc
% Close wait bar
delete(h);
if (outstate ~= out.failed)
% Assign outputs
seedinfo = seedinfo_prelim;
convergence = convergence_prelim;
outstate = out.success;
end
end