-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlsm_overlay.m
114 lines (88 loc) · 2.52 KB
/
vlsm_overlay.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
function vlsm_overlay(handles)
global VLSM
% Check SPM version
try
spmver = spm('ver');
catch
spmver = '';
end
if ~strcmpi(spmver,'SPM12'),
disp('Addpath SPM12 toolbox directory');
return
end
spm('Defaults', 'fMRI');
% Change 'Run' button color
set(handles.pushbutton_runGroup,'ForegroundColor',[1 1 1]);
set(handles.pushbutton_runGroup,'BackgroundColor',[11 132 199]./256);
pause(0.2);
% Get Parameters from VLSM
DATApath = VLSM.DATApath;
subjlist = VLSM.subjname;
nsubj = length(subjlist);
ROIfolder = VLSM.ROIfolder;
ROIprefix = VLSM.ROIprefix;
groupVar = VLSM.groupVar;
group = VLSM.group;
ngrp = VLSM.ngrp;
idg = unique(group);
% Output Path Setup
OUTpath = fullfile(DATApath,'overlay',groupVar); mkdir(OUTpath);
% Load reference
fn_tmp = sprintf('w%s%s.nii',ROIprefix,subjlist{1});
fn_roi = fullfile(DATApath, ROIfolder, fn_tmp);
if ~spm_existfile(fn_roi)
pause(0.5);
[p,f,e] = fileparts(fn_roi);
text_status = sprintf('File "%s" does not exist.', [f e]);
set(handles.text_status,'String',text_status);
disp(text_status);
return;
end
vref = spm_vol(fn_roi);
idbrainmask = fmri_load_maskindex(vref);
% Overlay Imaging data
if ngrp>1,
IMG = zeros([ngrp, prod(vref.dim)]);
else
IMG = zeros([1, prod(vref.dim)]);
end
for c=1:nsubj,
fn_tmp = sprintf('w%s%s.nii',ROIprefix, subjlist{c});
fn_roi = fullfile(DATApath, ROIfolder, fn_tmp);
vo = spm_vol(fn_roi);
I = spm_read_vols(vo);
%idx = find(I>0);
idroi = find(I>0);
idx = intersect(idbrainmask, idroi);
if ngrp>1,
IMG(group(c),idx) = IMG(group(c),idx) + 1;
else
IMG(1,idx) = IMG(1,idx) + 1;
end
end
% Write the resulting overlay image
if ngrp>1,
for i=1:ngrp,
Iout = zeros(vref.dim);
idsubj = find(group==idg(i));
fn = sprintf('overlay_grp%d_nsubj%d.nii',idg(i),length(idsubj));
v = vref;
v.dt = [16 0];
v.fname = fullfile(OUTpath, fn);
Iout = reshape(IMG(i,:),vref.dim);
spm_write_vol(v, Iout);
end
end
fn = sprintf('overlay_all_nsubj%d.nii',nsubj);
v = vref;
v.dt = [16 0];
v.fname = fullfile(OUTpath, fn);
if ngrp>1, Iout = reshape(sum(IMG), vref.dim);
else, Iout = reshape(IMG,vref.dim); end
spm_write_vol(v, Iout);
% Change 'Run' button color to the original
set(handles.pushbutton_runGroup,'ForegroundColor',[0 0 0]);
set(handles.pushbutton_runGroup,'BackgroundColor',[248 248 248]./256);
pause(0.5);
text_status = sprintf('overlay image was created.');
set(handles.text_status,'String',text_status);