-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator_structBased.m
More file actions
110 lines (90 loc) · 3.45 KB
/
validator_structBased.m
File metadata and controls
110 lines (90 loc) · 3.45 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
% addpath("/home/neuromedia/SLANTbrainSeg-updated/matlab");
run('config.m') %read configs
resultsPath = predPath;
refrencePath = psegPath;
structures = [ "hipp"; "hipp"; "amyg"; "amyg";...
"put"; "put";"pall"; "pall";"CWM"; "CWM";...
"3rdVentricle";"fusiform";"fusiform";...
"precuneus"; "precuneus";"CorpusCallosum";...
"CorpusCallosum"; "Thalamus";"Thalamus" ];
map = [ 2, 53; %Right-Hippocampus
1, 17; %Left-Hippocampus
2, 54; %Right-Amygdala
1, 18; %Left-Amygdala
2, 51; %Right-Putamen
1, 12; %Left-Putamen
2, 52; %Right-Pallidum
1, 13; %left-Pallidum
2, 46; %Right-CWM
1, 7; %Left-CWM
1, 14; %3rd-Ventricle
2, 1007; %Left-Fusiform
1, 2007; %Right-Fusiform
2, 2025; %Right-Precuneus
1, 1025; %Left-Precuneus
2, 2004; %Right-CorpusCallosum
1, 1004; %Left-CorpusCallosums
1, 10; % Left Thalamus
2, 49]; % Right Thalamus
resSublist = dir([resultsPath filesep convertStringsToChars(structures(1)) filesep '*.nii.gz']);
DCs = zeros(length(resSublist), length(map(:,1)));
sens = zeros(length(resSublist), length(map(:,1)));
specs = zeros(length(resSublist), length(map(:,1)));
for s=1:length(structures)
resSublist = dir([resultsPath filesep convertStringsToChars(structures(s)) filesep '*.nii.gz']);
refSublist = dir([refrencePath filesep convertStringsToChars(structures(s)) filesep '*.nii.gz']);
% sl = map(s,1);
% fl = mapSLANT2FS(sl, map); %map slant label to corresponding FS lbl
%for each MR image
for i = 1:length(resSublist)
fprintf("preparing image: %d - \n", i)
resPath = [resSublist(i).folder filesep resSublist(i).name] ;
refPath = [refSublist(i).folder filesep refSublist(i).name] ;
resMRImg = niftiread(resPath);
refMRImg = niftiread(refPath);
% refMRImg = rotator(refMRImg);
resFlag = flagger(resMRImg, map(s,1));
refFlag = flagger(refMRImg, map(s,2));
compareVis(resFlag, refFlag, 20);
DCs(i,s) = diceCoeff(resFlag, refFlag);
% ASSDs(i,s) =
[sens(i,s),specs(i,s)] = senSpec(resFlag, refFlag);
end
end
SmplBasedADC = mean(DCs, 2);
lblBasedADC = mean(DCs, 1);
% FUNCTIONS
function [sen , spec] = senSpec(resFlag, refFlag)
comb = single(resFlag) + 3*single(refFlag);
sen = (length(find(comb==4))/(length(find(comb==4))+length(find(comb==1))))*100;
spec = (length(find(comb==0))/(length(find(comb==1))+length(find(comb==0))))*100;
end
function res = diceCoeff (resFlag, refFlag)
comb = single(resFlag) + single(refFlag);
intersec = length(find(comb==2));
res = ((2*(intersec))/(length(find(resFlag==1))+length(find(refFlag==1))))*100;
end
function resFlag = flagger(img, lbl)
resFlag = img;
resFlag(resFlag ~= lbl) = 0;
resFlag(resFlag == lbl) = 1;
end
function compareVis(resImg, refImg, slice)
% if isempty(slice); slice = 128; end
if nargin < 3; slice = 84; end
figure(2);
subplot(1,2,1);
imshow(resImg(:,:,slice),[])
title('Result image');
subplot(1,2,2);
imshow(refImg(:,:,slice),[])
title('Reference image');
end
function res = rotator(img)
figure(1);
res = zeros(size(img));
for i = 1:size(img, 3)
res(:,:,i) = flipdim(img(:,:,i), 2);
imshow(res(:,:,i), [])
end
end