forked from yetianmed/subcortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvm_test.m
50 lines (31 loc) · 1.03 KB
/
svm_test.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
function [y_img,dice]=svm_test(img_dil,Out,s_test,ind)
% INPUT
% img_dil:3-D image (matrix) comprises region of interest and its uncertainty zone
% Out: classifier computed from svm_train.m
% s_test: similarity matrix of new subject in testing samples
% ind: index of all subcortical voxels in the 3-D atlas image (MNI152 space)
% OUTPUT
% y_img: probabilistic map
% dice: dice coefficient
Nxyz=size(img_dil);
Mdl=Out.Mdl;
ScoreMdl=Out.ScoreMdl;
y_gt=Out.y_gt;
ind1=find(img_dil(ind)==1); %class 1: other regions
ind2=find(img_dil(ind)==2); %class 2: region
ind_both=[ind1;ind2];
ind_out=setdiff(1:length(ind),ind_both);
s_test=s_test(ind_both,ind_out); %voxels x features x subjects
y_img=zeros(Nxyz);
y_pred=predict(Mdl,s_test);
[~,tmp]=predict(ScoreMdl,s_test);
%y_pred_score=tmp(:,2);
tmp_img=zeros(Nxyz);
tmp_img(ind(ind_both))=tmp(:,2);
y_img(:,:,:)=tmp_img;
%Dice coefficient
common=(y_pred==2 & y_gt==2);
a = sum(common(:));
b = sum(y_pred==2);
c = sum(y_gt==2);
dice=2*a/(b+c);