-
Notifications
You must be signed in to change notification settings - Fork 3
/
Step1ExtractMetrics.m
123 lines (103 loc) · 4.07 KB
/
Step1ExtractMetrics.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
function MetricsMatrix = Step1ExtractMetrics(path, StudyType)
% NAStep1ExtractMetricsME - this main function extract all metrics from the path root directory and recursively explore any subsequent folders that contain all DICOM files.
%
% Syntax: [output1,output2] = function_name(input1,input2,input3)
%
% Inputs:
% path - the root directory where all DICOM files are located.
%
% Outputs:
% MetricsMatrix - aggregated matrix containing all metrics extracted in a 2D array for ML
% Output - structure contain all indiviudal humanly readable metrics for data storage purposes.
%
% Example:
% Line 1 of example
% Line 2 of example
% Line 3 of example
%
% Other m-files required: RecursivelyLoadDICOM.m, LoadConfigVariables.m
% MAT-files required: none
%
% See also: OTHER_FUNCTION_NAME1, OTHER_FUNCTION_NAME2
% Author: Yang Ding
% All works sponsored by Dr. Gregory Lodygensky and the Canadian Neonatal Brain Platform
% Saint. Justine Hospital, Montreal, Quebec,
% email address: it@cnbp.ca
% Website: http://cnbp.ca
% 2017; Last revision: 2017-08-14 22:45:37 Eastern Time
%------------- BEGIN CODE --------------
% Read in the setting files
Settings = LoadConfigVariables();
% Get current path of current script.
scriptName = mfilename('fullpath');
% Ensure dependencies are properly referred to by recursively add the folder and subdirectories.
addpath(genpath(Settings.Folder.Root));
addpath(genpath(Settings.Folder.Result));
addpath(genpath(Settings.Folder.NSSMetrics));
addpath(genpath(Settings.Folder.FocusMetrics));
addpath(genpath(Settings.Folder.General));
addpath(genpath(Settings.Folder.SNRMetrics));
addpath(genpath(Settings.Folder.TextureMetrics));
addpath(genpath(Settings.Folder.DICOM));
addpath(genpath(Settings.Folder.General));
%Update Windows System environment variables to ensure that the SVM-predict etc can be utilized.
setenv('SVMLib',Settings.Folder.SVMLib);
tic;
% Use GUI to get path to the folder that contained all the DICOM files.
% path = uigetdir;
% Get output.
Output = ParRecursivelyLoadDICOM(path);
% Put everything in a gigantic matrix for further analyses.
MetricsMatrix = cat (2, ...
Output.FocusMetrics, ...
Output.SNRMetrics, ...
Output.TextureMetrics, ...
Output.NSSMetrics, ...
Output.DICOMMetrics ...
);
%Save EXTRA copy of the data in the final folder AS WELL as the regular output folder.
cd(Settings.Folder.Result);
if (exist(StudyType))
if (StudyType == 'ASP')
Output.Dir = Settings.Folder.ASPMetrics;
% Enter the output folder
mkdir (Output.Dir)
cd (Output.Dir)
% Save the various output
save('MetricsDataStructure.mat','Output')
save('MetricsMatrix.mat','MetricsMatrix')
csvwrite('UnlabledMatrix.csv','MetricsMatrix');
OutputTable = array2table(MetricsMatrix,'VariableNames',Output.LabelAggregate);
writetable(OutputTable,'LabeledMatrix.csv');
elseif (StudyType == 'BDP')
Output.Dir = Settings.Folder.BDPMetrics;
% Enter the output folder
mkdir (Output.Dir)
cd (Output.Dir)
% Save the various output
save('MetricsDataStructure.mat','Output')
save('MetricsMatrix.mat','MetricsMatrix')
csvwrite('UnlabledMatrix.csv','MetricsMatrix');
OutputTable = array2table(MetricsMatrix,'VariableNames',Output.LabelAggregate);
writetable(OutputTable,'LabeledMatrix.csv');
end
end
%Regular saving process flow.
%Enter Results directory, save the metrics computed.
cd(Settings.Folder.Result);
% Record and enter the specific directory
Output.Dir = mkdirNowPrefix('MetricsComputation');
% Enter the output folder
cd (Output.Dir)
% Save the various output
save('MetricsDataStructure.mat','Output');
save('MetricsMatrix.mat','MetricsMatrix');
csvwrite('UnlabledMatrix.csv',MetricsMatrix);
OutputTable = array2table(MetricsMatrix,'VariableNames',Output.LabelAggregate);
writetable(OutputTable,'LabeledMatrix.csv');
% Return to root.
cd(Settings.Folder.Root);
disp('Step 1 Completed:')
toc
%------------- END OF CODE --------------
end