Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vaanathi Sundaresan
LOCATE-BIANCA
Commits
b52bc158
Commit
b52bc158
authored
Aug 01, 2019
by
Vaanathi Sundaresan
Browse files
Replace LOCATE_testing_highdim.m
parent
d1da7807
Changes
1
Hide whitespace changes
Inline
Side-by-side
LOCATE_testing_highdim.m
View file @
b52bc158
...
...
@@ -25,14 +25,19 @@ if nargin > 0
end
% Assigning the Root directories
root_data_directory
=
t
raining
_image_directory_name
;
results_directory
=
sprintf
(
'%s/LOCATE_
LOO_
results_directory'
,
t
raining
_image_directory_name
);
root_data_directory
=
t
est
_image_directory_name
;
results_directory
=
sprintf
(
'%s/LOCATE_results_directory'
,
t
est
_image_directory_name
);
xdir
=
dir
(
sprintf
(
'%s/*_BIANCA_LPM.nii.gz'
,
root_data_directory
));
% Creating the results directory
if
~
exist
(
results_directory
)
mkdir
(
results_directory
)
end
xdir
=
dir
(
sprintf
(
'%s/*_BIANCA_LPM.nii.gz'
,
train_image_directory_name
));
if
numel
(
xdir
)
==
0
error
(
'Cannot find any input image. Please check your training_image_directoy_name'
);
error
(
'Cannot find any input image. Please check your training_image_directoy_name
'
);
else
xdir
=
dir
(
sprintf
(
'%s/*_BIANCA_LPM.nii.gz'
,
root_data_directory
));
xsplit
=
regexp
(
xdir
(
1
)
.
name
,
'_BIANCA_LPM'
,
'split'
);
xfeats
=
dir
(
sprintf
(
'%s/%s_feature_*'
,
root_data_directory
,
xsplit
{
1
}));
if
numel
(
xfeats
)
==
0
...
...
@@ -43,9 +48,9 @@ end
numfeats
=
numel
(
xfeats
);
feature_selection_cols
=
ones
(
numfeats
+
2
,
1
);
if
nargin
>
1
if
nargin
>
2
if
numel
(
varargin
{
2
})
==
1
error
(
'
Secon
d input (feature_select) must be a vector with number of elements equal to the number of features specified.'
);
error
(
'
Thir
d input (feature_select) must be a vector with number of elements equal to the number of features specified.'
);
elseif
numel
(
varargin
{
2
})
<
numfeats
+
2
error
(
'Number of columns in feature_select does not match the number of features specified.'
);
else
...
...
@@ -54,27 +59,33 @@ if nargin > 1
end
verbose
=
0
;
if
nargin
>
2
if
nargin
>
3
verbose
=
varargin
{
3
};
end
if
verbose
feature_selection_cols
train
ing
_image_directory_name
train_image_directory_name
end
% Creating the results directory
if
~
exist
(
results_directory
)
mkdir
(
results_directory
)
% Loading the Trained Regression model
try
load
(
sprintf
(
'%s/LOCATE_training_files/RF_regression_model_LOCATE.mat'
,
train_image_directory_name
));
catch
error
(
'Training model not found. Run LOCATE_training first or check the training images directory'
);
end
if
sum
(
feature_selection_cols
)
~=
(
size
(
RFmodel
.
X
,
2
)/
20
)
error
(
'The number of features selected does not match the features used to train the model. Kindly check your feature_select input or use a different model.'
);
end
xdir
=
dir
(
sprintf
(
'%s/*_BIANCA_LPM.nii.gz'
,
root_data_directory
));
imgfeatmats
=
cell
(
numel
(
xdir
),
1
);
ventdistfeatmats
=
cell
(
numel
(
xdir
),
1
);
lesvolfeatmats
=
cell
(
numel
(
xdir
),
1
);
index_indices_list
=
cell
(
numel
(
xdir
),
1
);
index_maps
=
cell
(
numel
(
xdir
),
1
);
for
subj
=
1
:
numel
(
xdir
)
if
verbose
...
...
@@ -205,60 +216,23 @@ for testsubj = 1:numel(xdir)
xsplit
=
regexp
(
xdir
(
testsubj
)
.
name
,
'_BIANCA_LPM'
,
'split'
);
lesionmaskfile
=
sprintf
(
'%s/%s_BIANCA_LPM.nii.gz'
,
root_data_directory
,
xsplit
{
1
});
lesionmask
=
read_avw
(
lesionmaskfile
);
load
(
sprintf
(
'%s/LOCATE_features_%s.mat'
,
results_directory
,
xsplit
{
1
}))
% Defining the indicies of trainign subjects as everything except the
% current test subject
trainsubjects
=
setdiff
(
1
:
numel
(
xdir
),
testsubj
);
fprintf
(
'trainsubjects identified! \n'
);
% Concatenating the training features
trainflairfeatmat
=
[];
trainventdistfeatmat
=
[];
trainlesvolfeatmat
=
[];
trainminbestthrs
=
[];
trainmaxbestthrs
=
[];
trainmeanbestthrs
=
[];
for
trainsubj
=
1
:
numel
(
trainsubjects
)
trainflairfeatmat
=
[
trainflairfeatmat
;
imgfeatmats
{
trainsubjects
(
trainsubj
)}];
trainventdistfeatmat
=
[
trainventdistfeatmat
;
ventdistfeatmats
{
trainsubjects
(
trainsubj
)}];
trainlesvolfeatmat
=
[
trainlesvolfeatmat
;
lesvolfeatmats
{
trainsubjects
(
trainsubj
)}];
trainminbestthrs
=
[
trainminbestthrs
;
minbestthrs
{
trainsubjects
(
trainsubj
)}];
trainmaxbestthrs
=
[
trainmaxbestthrs
;
maxbestthrs
{
trainsubjects
(
trainsubj
)}];
trainmeanbestthrs
=
[
trainmeanbestthrs
;
meanbestthrs
{
trainsubjects
(
trainsubj
)}];
end
voronoi_train_features_all
=
[
trainventdistfeatmat
,
trainlesvolfeatmat
,
trainflairfeatmat
];
if
verbose
fprintf
(
'Voronoi training features has been collected! \n'
);
end
threshold_array
=
0
:
0.05
:
0.95
;
feature_selection_cols_exp
=
repmat
(
feature_selection_cols
,
[
numel
(
threshold_array
),
1
]);
feature_selection_cols_exp
=
feature_selection_cols_exp
(:)
'
;
voronoi_train_features
=
voronoi_train_features_all
(:,
feature_selection_cols_exp
>
0
);
% Training RF regression model using all the feataures except the test
% subject
RFmodel_LOO
=
TreeBagger
(
1000
,
voronoi_train_features
,
trainmaxbestthrs
,
'Method'
,
'Regression'
,
...
'numPredictorsToSample'
,
'all'
);
if
verbose
fprintf
(
'Training done! \n'
);
end
% Extract the corresponding test features and index masks from cell
% arrays
testflairfeatmat
=
imgfeatmats
{
testsubj
};
testventdistfeatmat
=
ventdistfeatmats
{
testsubj
};
testlesvolfeatmat
=
lesvolfeatmats
{
testsubj
};
%
index_mask = index_maps{testsubj};
index_numbers
=
setdiff
(
union
(
index_mask
(:),[]),
0
);
%
index_indices_list{testsubj};
index_mask
=
index_maps
{
testsubj
};
index_numbers
=
index_indices_list
{
testsubj
};
voronoi_test_features_all
=
[
testventdistfeatmat
,
testlesvolfeatmat
,
testflairfeatmat
];
if
verbose
fprintf
(
'Voronoi test features has been collected! \n'
);
end
threshold_array
=
0
:
0.05
:
0.95
;
feature_selection_cols_exp
=
repmat
(
feature_selection_cols
,
[
numel
(
threshold_array
),
1
]);
feature_selection_cols_exp
=
feature_selection_cols_exp
(:)
'
;
voronoi_test_features
=
voronoi_test_features_all
(:,
feature_selection_cols_exp
>
0
);
testmeanbestthrs
=
predict
(
RFmodel
_LOO
,
voronoi_test_features
);
testmeanbestthrs
=
predict
(
RFmodel
,
voronoi_test_features
);
%Assigning the values to the final image
final_binary_lesionmask
=
zeros
(
size
(
lesionmask
));
...
...
@@ -272,10 +246,10 @@ for testsubj = 1:numel(xdir)
threshold_mask
=
threshold_mask
+
thresh
;
final_binary_lesionmask
=
final_binary_lesionmask
|
binary_voronoi_lesionmask
;
end
%
lesion_masks{testsubj} = final_binary_lesionmask;
%
thresholds{testsubj} = testmeanbestthrs;
%
thresholdmap{testsubj} = threshold_mask;
%
indexmaps{testsubj} = index_mask;
lesion_masks
{
testsubj
}
=
final_binary_lesionmask
;
thresholds
{
testsubj
}
=
testmeanbestthrs
;
thresholdmap
{
testsubj
}
=
threshold_mask
;
indexmaps
{
testsubj
}
=
index_mask
;
% Saving the images
save_avw
(
index_mask
,
sprintf
(
'%s/%s_indexmap.nii.gz'
,
results_directory
,
xsplit
{
1
}),
'f'
,[
1
1
1
]);
...
...
@@ -286,7 +260,8 @@ for testsubj = 1:numel(xdir)
copying_image_geometry
(
lesionmaskfile
,
sprintf
(
'%s/%s_indexmap.nii.gz'
,
results_directory
,
xsplit
{
1
}),
verbose
);
copying_image_geometry
(
lesionmaskfile
,
sprintf
(
'%s/%s_thresholdsmap.nii.gz'
,
results_directory
,
xsplit
{
1
}),
verbose
);
copying_image_geometry
(
lesionmaskfile
,
sprintf
(
'%s/%s_BIANCA_LOCATE_binarylesionmap.nii.gz'
,
results_directory
,
xsplit
{
1
}),
verbose
);
end
% Save all the results as a consolidated single folder
%
save(sprintf('%s/Consolidated_LOCATE_output.mat',results_directory),'lesion_masks','thresholds','indexmaps','thresholdmap');
save
(
sprintf
(
'%s/Consolidated_LOCATE_output.mat'
,
results_directory
),
'lesion_masks'
,
'thresholds'
,
'indexmaps'
,
'thresholdmap'
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment