-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExecutionClass.m
More file actions
235 lines (180 loc) · 6.27 KB
/
ExecutionClass.m
File metadata and controls
235 lines (180 loc) · 6.27 KB
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
classdef ExecutionClass < handle
% Main controller class for EyeFlow execution and analysis.
% Coordinates between specialized modules.
properties
% Basic Info
path char
directory char
params_names cell
param_name char
filenames char
% Modules
Analyzer AnalyzerClass
Reporter ReporterClass
% Input Data
M0 single
M1 single
M2 single
SH single
% AI Networks
AINetworks AINetworksClass
% Processing Flags
is_preprocessed = false
is_segmented = false
is_velocityAnalyzed = false
is_volumeRateAnalyzed = false
is_AllAnalyzed = false
% Checkbox flags
flag_segmentation logical
flag_bloodFlowVelocity_analysis logical
flag_pulseWaveVelocity logical
flag_crossSection_analysis logical
flag_crossSection_export logical
flag_spectral_analysis logical
% Components
ToolBoxMaster ToolBoxClass
Output OutputClass
Cache CacheClass
end
methods
function obj = ExecutionClass(path)
% Constructor for the class, initializes all components
tLoading = tic;
fprintf("\n----------------------------------\n" + ...
"Video Loading\n" + ...
"----------------------------------\n");
% Initialize DataLoader first
DataLoader = DataLoaderClass(path);
% Copy data to ExecutionClass for backward compatibility
obj.directory = DataLoader.directory;
obj.filenames = DataLoader.filenames;
obj.path = path;
% Copy data to ExecutionClass for backward compatibility
obj.M0 = DataLoader.M0;
obj.M1 = DataLoader.M1;
obj.M2 = DataLoader.M2;
obj.SH = DataLoader.SH;
clear DataLoader;
% Load parameters
obj.params_names = checkEyeFlowParamsFromJson(obj.directory);
obj.param_name = obj.params_names{1};
% Initialize Output and Cache
obj.Output = OutputClass();
obj.Cache = CacheClass();
% Initialize Modules
obj.Analyzer = AnalyzerClass(obj.Cache);
Parameters_json(path, obj.param_name);
fprintf("- Video Loading took : %ds\n", round(toc(tLoading)))
end
function preprocessData(obj)
PreProcessTimer = tic;
fprintf("\n----------------------------------\nVideo PreProcessing\n----------------------------------\n");
% Delegate to Preprocessor
Preprocessor = PreprocessorClass(obj.directory, obj.filenames, obj.param_name);
% Preprocessing
Preprocessor.preprocess(obj);
% Copy results back for backward compatibility
obj.Cache.firstFrameIdx = Preprocessor.firstFrameIdx;
obj.Cache.lastFrameIdx = Preprocessor.lastFrameIdx;
obj.Cache.M0_ff = Preprocessor.M0_ff;
obj.Cache.M0_ff_img = squeeze(mean(obj.Cache.M0_ff, 3));
obj.Cache.f_RMS = Preprocessor.f_RMS;
obj.Cache.f_AVG = Preprocessor.f_AVG;
obj.Cache.displacementField = Preprocessor.displacementField;
obj.is_preprocessed = Preprocessor.is_preprocessed;
% Clear Preprocessor and intermediate variables
obj.M0 = [];
obj.M1 = [];
obj.M2 = [];
obj.SH = [];
clear Preprocessor;
fprintf("- Preprocess took : %ds\n", round(toc(PreProcessTimer)))
fprintf("\n----------------------------------\nPreprocessing Complete\n----------------------------------\n");
end
function analyzeData(obj, app)
% Main analysis coordinator
% Initialize output system
AnalyzerTimer = tic;
ToolBox = obj.ToolBoxMaster;
params = ToolBox.getParams;
ToolBox.setOutput(obj.Output);
ToolBox.setCache(obj.Cache);
obj.Cache.createTimeVector(ToolBox, obj.Cache.lastFrameIdx);
obj.Cache.createFreqVector(ToolBox);
obj.Reporter = ReporterClass(obj);
if params.json.DebugMode
profile off
profile on
end
obj.AINetworks.updateAINetworks(params);
% Execute eye side analysis if asked
if params.json.Mask.EyeSideClassifierNet
predictEyeSide(obj.AINetworks.EyeSideClassifierNet);
end
% Execute analysis steps based on checkbox flags
if obj.flag_segmentation
obj.Analyzer.performSegmentation(obj, app);
end
if obj.flag_bloodFlowVelocity_analysis
obj.Analyzer.performPulseAnalysis(obj);
end
try
if obj.flag_pulseWaveVelocity
obj.Analyzer.performPulseVelocityAnalysis(obj);
end
catch ME
MEdisp(ME, '');
warning("Pulse Wave Velocity Analysis failed");
end
try
if obj.flag_crossSection_analysis
obj.Analyzer.performCrossSectionAnalysis(obj);
end
if obj.flag_crossSection_export
obj.Analyzer.generateexportCrossSectionResults(obj);
end
catch ME
MEdisp(ME, "", "WARN", "Cross-Section Analysis failed");
end
if obj.flag_spectral_analysis && ~isempty(obj.SH)
obj.Analyzer.performSpectralAnalysis(obj);
end
diary off;
if params.json.DebugMode
profile off
profile viewer
end
fprintf("- Total Analysis took : %ds\n", round(toc(AnalyzerTimer)))
end
function checkData(obj)
% Visual check of loaded/preprocessed data
figure
if ~isempty(obj.Cache.M0_ff)
subplot(2, 2, 1)
imagesc(mean(obj.Cache.M0_ff, 3))
axis image off
subplot(2, 2, 2)
imagesc(mean(obj.Cache.f_AVG, 3))
axis image off
subplot(2, 2, 3)
imagesc(mean(obj.Cache.f_RMS, 3))
axis image off
if ~isempty(obj.Cache.displacementField)
subplot(2, 2, 4)
imagesc(sqrt(mean(obj.Cache.displacementField .^ 2, 4)))
axis image off
end
elseif ~isempty(obj.M0)
subplot(1, 3, 1)
imagesc(mean(obj.M0, 3))
axis image off
subplot(1, 3, 2)
imagesc(mean(obj.M1, 3))
axis image off
subplot(1, 3, 3)
imagesc(mean(obj.M2, 3))
axis image off
end
end
end
end