-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlsm_normalization.m
153 lines (120 loc) · 6.37 KB
/
vlsm_normalization.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function vlsm_normalization(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_normalization,'ForegroundColor',[1 1 1]);
set(handles.pushbutton_normalization,'BackgroundColor',[11 132 199]./256);
pause(0.2);
% Get Parameters from VLSM
DATApath = VLSM.DATApath;
subjlist = VLSM.subjname;
nsubj = length(subjlist);
T1folder = VLSM.T1folder;
ROIfolder = VLSM.ROIfolder;
T1prefix= VLSM.T1prefix;
ROIprefix = VLSM.ROIprefix;
% Normalization Options
doSeg = VLSM.doSeg;
for c=1:nsubj,
pause(0.5);
text_status = sprintf('[%03d/%03d] normalizing for subj%s ...',c,nsubj,subjlist{c});
set(handles.text_status,'String',text_status);
% Load T1 Image data
fn_nii = struct([]);
fn_tmp = sprintf('%s%s.nii', T1prefix, subjlist{c});
fn_nii{1} = fullfile(DATApath, T1folder, fn_tmp);
% Load Lesion Image data
fn_tmp = sprintf('%s%s.nii', ROIprefix, subjlist{c});
fn_nii{2} = fullfile(DATApath, ROIfolder, fn_tmp);
% Load Template Image
fn_template = fullfile(spm('dir'),'tpm','TPM.nii');
if doSeg,
clear matlabbatch;
matlabbatch{1}.spm.spatial.preproc.channel.vols = {fn_nii{1}};
matlabbatch{1}.spm.spatial.preproc.channel.biasreg = 0.001;
matlabbatch{1}.spm.spatial.preproc.channel.biasfwhm = 60;
matlabbatch{1}.spm.spatial.preproc.channel.write = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(1).tpm = {[fn_template ',1']};
matlabbatch{1}.spm.spatial.preproc.tissue(1).ngaus = 1;
matlabbatch{1}.spm.spatial.preproc.tissue(1).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(1).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(2).tpm = {[fn_template ',2']};
matlabbatch{1}.spm.spatial.preproc.tissue(2).ngaus = 1;
matlabbatch{1}.spm.spatial.preproc.tissue(2).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(2).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(3).tpm = {[fn_template ',3']};
matlabbatch{1}.spm.spatial.preproc.tissue(3).ngaus = 2;
matlabbatch{1}.spm.spatial.preproc.tissue(3).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(3).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(4).tpm = {[fn_template ',4']};
matlabbatch{1}.spm.spatial.preproc.tissue(4).ngaus = 3;
matlabbatch{1}.spm.spatial.preproc.tissue(4).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(4).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(5).tpm = {[fn_template ',5']};
matlabbatch{1}.spm.spatial.preproc.tissue(5).ngaus = 4;
matlabbatch{1}.spm.spatial.preproc.tissue(5).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(5).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(6).tpm = {[fn_template ',6']};
matlabbatch{1}.spm.spatial.preproc.tissue(6).ngaus = 2;
matlabbatch{1}.spm.spatial.preproc.tissue(6).native = [0 0];
matlabbatch{1}.spm.spatial.preproc.tissue(6).warped = [0 0];
matlabbatch{1}.spm.spatial.preproc.warp.mrf = 1;
matlabbatch{1}.spm.spatial.preproc.warp.cleanup = 1;
matlabbatch{1}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2];
matlabbatch{1}.spm.spatial.preproc.warp.affreg = 'eastern';
matlabbatch{1}.spm.spatial.preproc.warp.fwhm = 0;
matlabbatch{1}.spm.spatial.preproc.warp.samp = 3;
matlabbatch{1}.spm.spatial.preproc.warp.write = [0 1];
%spm_jobman('interactive',matlabbatch); % open a GUI containing all the setup
spm_jobman('run',matlabbatch);
% Load tranformation generated by Segmentation
fn_y = sprintf('y_%s%s.nii', T1prefix, subjlist{c});
fn_y = fullfile(DATApath, T1folder, fn_y);
%------------------------------------------------------------------
% Normalization
%------------------------------------------------------------------
clear matlabbatch;
matlabbatch{1}.spm.spatial.normalise.write.subj.def = {fn_y};
matlabbatch{1}.spm.spatial.normalise.write.subj.resample = [fn_nii'];
matlabbatch{1}.spm.spatial.normalise.write.woptions.bb = [-78 -112 -70; 78 76 85];
matlabbatch{1}.spm.spatial.normalise.write.woptions.vox = [2 2 2];
matlabbatch{1}.spm.spatial.normalise.write.woptions.interp = 0; % resample in nearest neighbor
%spm_jobman('interactive',matlabbatch); % open a GUI containing all the setup
spm_jobman('run',matlabbatch);
else
%------------------------------------------------------------------
% Normalization
%------------------------------------------------------------------
clear matlabbatch;
matlabbatch{1}.spm.spatial.normalise.estwrite.subj.vol = {fn_nii{1}};
matlabbatch{1}.spm.spatial.normalise.estwrite.subj.resample = [fn_nii'];
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.biasreg = 0.0001;
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.biasfwhm = 60;
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.tpm = {fn_template};
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.affreg = 'eastern';
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.reg = [0 0.001 0.5 0.05 0.2];
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.fwhm = 0;
matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.samp = 3;
matlabbatch{1}.spm.spatial.normalise.estwrite.woptions.bb = [-78 -112 -70; 78 76 85];
matlabbatch{1}.spm.spatial.normalise.estwrite.woptions.vox = [2 2 2];
matlabbatch{1}.spm.spatial.normalise.estwrite.woptions.interp = 0; % resample in nearest neighbor
%spm_jobman('interactive',matlabbatch); % open a GUI containing all the setup
spm_jobman('run',matlabbatch);
end
end
% Change 'Run' button color to the original
set(handles.pushbutton_normalization,'ForegroundColor',[0 0 0]);
set(handles.pushbutton_normalization,'BackgroundColor',[248 248 248]./256);
pause(0.5);
text_status = sprintf('normalization processes were done.');
set(handles.text_status,'String',text_status);