-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPreprocessorClass.m
More file actions
163 lines (126 loc) · 4.28 KB
/
PreprocessorClass.m
File metadata and controls
163 lines (126 loc) · 4.28 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
classdef PreprocessorClass < handle
% Handles all preprocessing operations
properties
is_preprocessed = false
M0_ff double
M0 double
M1 double
M2 double
SH double
f_RMS double
f_AVG double
directory char
filenames char
param_name char
displacementField
firstFrameIdx double
lastFrameIdx double
end
methods
function obj = PreprocessorClass(directory, filenames, param_name)
obj.directory = directory;
obj.filenames = filenames;
obj.param_name = param_name;
end
function preprocess(obj, executionObj)
if any(isnan(executionObj.M0), 'all')
error('NaN values found in M0 data. Please check the input file.');
end
params = Parameters_json(obj.directory, obj.param_name);
obj.M0 = executionObj.M0;
obj.M1 = executionObj.M1;
obj.M2 = executionObj.M2;
obj.SH = executionObj.SH;
% Execute preprocessing steps
obj.register(params);
obj.crop(params);
obj.normalizeLocally(params);
obj.resize(params);
obj.nonRigidRegister(params);
obj.interpolate(params);
obj.removeOutliers(params);
obj.is_preprocessed = true;
end
end
methods (Access = private)
function register(obj, params)
firstFrame = params.json.Preprocess.Register.StartFrame;
lastFrame = params.json.Preprocess.Register.EndFrame;
enableRegistration = params.json.Preprocess.Register.Enable;
if (firstFrame == 1) && (lastFrame == -1) || ~enableRegistration
return % do nothing if not required
end
tic
fprintf(" - Video Registering...\n");
% Rigid registration implementation
VideoRegistering(obj, firstFrame, lastFrame);
fprintf(" - Video Registration took: %ds\n", round(toc));
end
function crop(obj, params)
firstFrame = params.json.Preprocess.Crop.StartFrame;
lastFrame = params.json.Preprocess.Crop.EndFrame;
obj.firstFrameIdx = 1;
obj.lastFrameIdx = size(obj.M0, 3);
if (firstFrame == 1) && (lastFrame == -1)
return % do nothing if not required
end
tic
fprintf(" - Video Cropping...\n");
% Cropping implementation
[firstFrameOut, lastFrameOut] = VideoCropping(obj, firstFrame, lastFrame);
if firstFrameOut ~= firstFrame
obj.firstFrameIdx = firstFrameOut;
end
if lastFrameOut ~= lastFrame
obj.lastFrameIdx = lastFrameOut;
end
fprintf(" - Video Cropping took: %ds\n", round(toc));
end
function normalizeLocally(obj, params)
tic
fprintf(" - Local Normalization...\n");
% Local normalization implementation
VideoNormalizingLocally(obj, params);
fprintf(" - Local Normalization took: %ds\n", round(toc));
end
function resize(obj, params)
tic
fprintf(" - Video Resizing...\n");
% Resizing implementation
VideoResizing(obj, params);
fprintf(" - Video Resizing took: %ds\n", round(toc));
end
function nonRigidRegister(obj, params)
if ~params.json.Preprocess.NonRigidRegisteringFlag
return
end
apply = params.json.Preprocess.NonRigidRegisteringApply;
tic
fprintf(" - Video Non-Rigid Registration...\n");
% Non-rigid registration implementation
VideoNonRigidRegistering(obj, apply);
fprintf(" - Video Non-Rigid Registration took: %ds\n", round(toc));
end
function interpolate(obj, params)
kInterp = params.json.Preprocess.InterpolationFactor;
if kInterp == 0
return
end
tic
fprintf(" - Video Interpolating...\n");
% Interpolation implementation
VideoInterpolating(obj, params);
fprintf(" - Video Interpolation took: %ds\n", round(toc));
end
function removeOutliers(obj, params)
if ~params.json.Preprocess.RemoveOutliersFlag
return
end
tic
fprintf(" - Video Outlier Removal...\n");
% Outlier removal implementation
VideoRemoveOutliers(obj, params);
fprintf(" - Video Outlier Removal took: %ds\n", round(toc));
end
end
end