-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathhmri_run_proc_US.m
117 lines (109 loc) · 4.37 KB
/
hmri_run_proc_US.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
function out = hmri_run_proc_US(job)
% Deal with the spatial preprocessing, 1 subject at a time: segmentation of
% the MT and T1 images
%_______________________________________________________________________
% Copyright (C) 2017 Cyclotron Research Centre
% Written by Christophe Phillips
% but largely inspired by the batch from the past VBQ toolbox.
% Turning data organization from "per image type" into "per subject"
% because data are processed subject per subject.
% This relies alos on the previous toolbox, which allowed explicitly for a
% "per subject" setting of the data, so here we keep about the same code.
job = preproc_perimage_to_persubject(job);
% Initiliazign the output structure 'out'
% .tiss : struct-array with subfields
% .c and .rc, for the native and Dartel imported
% .wc and .mwc, for the warped and modulated
% tissue class images
% .maps : struct-array with subfields 'wvols_pm' for the warped parametric
% maps
% .def : cell-array with the deformations for each subject.
for i=1:numel(job.tissue)
out.tiss(i).c = {};
out.tiss(i).rc = {};
out.tiss(i).wc = {};
out.tiss(i).mwc = {};
end
if numel(job.subjc(1).maps.vols_pm)
for i=1:numel(job.subjc(1).maps.vols_pm)
out.maps(i).wvols_pm = {};
end
else
out.maps.wvols_pm = {};
end
out.def.fn = {};
% looping over all the subjects.
for nm = 1:length(job.subjc)
% Prepare and run 'spm_preproc' -> get tissue maps + deformation
defsa.channel = job.subjc(nm).channel;
% defsa.channel = job.subjc(nm).struct(1);
% defsa.channel.vols = job.subjc(nm).struct(1).s_vols;
defsa.tissue = job.tissue;
defsa.warp = job.warp;
out.subjc(nm) = spm_preproc_run(defsa);
% Apply deformation on maps + get deformation map name
defs.comp{1}.def = spm_file(job.subjc(nm).channel(1).vols, ...
'prefix', 'y_', 'ext', '.nii'); % def map fname
% defs.ofname = '';
if numel(job.subjc(nm).maps.vols_pm)
defs.out{1}.pull.fnames = cellstr(char(char(job.subjc(nm).maps.vols_pm{:})));
if isfield(job.subjc(nm).output,'indir') && job.subjc(nm).output.indir == 1
defs.out{1}.pull.savedir.saveusr{1} = ...
spm_file(job.subjc(nm).maps.vols_pm{1},'path');
else
defs.out{1}.pull.savedir.saveusr{1} = job.subjc(nm).output.outdir{1};
end
defs.out{1}.pull.interp = 1;
defs.out{1}.pull.mask = 1;
defs.out{1}.pull.fwhm = [0 0 0]; % no smoothing requester,
% though at least vx_size/4 smoothing will still be applied!
outdef = spm_deformations(defs);
else
outdef.warped = {};
end
% Save filenames as apropriate for 'out'
for i=1:numel(out.subjc(1).tiss)
if isfield(out.subjc(nm).tiss(i), 'c')
out.tiss(i).c = [out.tiss(i).c; out.subjc(nm).tiss(i).c];
end
if isfield(out.subjc(nm).tiss(i), 'rc')
out.tiss(i).rc = [out.tiss(i).rc; out.subjc(nm).tiss(i).rc];
end
if isfield(out.subjc(nm).tiss(i), 'wc')
out.tiss(i).wc = [out.tiss(i).wc; out.subjc(nm).tiss(i).wc];
end
if isfield(out.subjc(nm).tiss(i), 'mwc')
out.tiss(i).mwc = [out.tiss(i).mwc; out.subjc(nm).tiss(i).mwc];
end
end
for i=1:numel(outdef.warped)
out.maps(i).wvols_pm{end+1,1} = outdef.warped{i};
end
out.def.fn{end+1,1} = defs.comp{1}.def{1};
end
end
% ========================================================================
%% SUBFUNCTIONS
% ========================================================================
function job = preproc_perimage_to_persubject(job)
% Rearrange data per subject for further preprocessing.
% Number of subjects from 1st set of structurals for segmentation
nSubj = numel(job.many_sdatas.channel(1).vols);
nChan = numel(job.many_sdatas.channel);
nPara = numel(job.many_sdatas.vols_pm);
for ii = 1:nSubj
job.subjc(ii).output = job.many_sdatas.output;
% Collect structurals
job.subjc(ii).channel = job.many_sdatas.channel;
for jj = 1:nChan
job.subjc(ii).channel(jj).vols = job.many_sdatas.channel(jj).vols(ii);
end
% Collect parametric maps to warp, if any
job.subjc(ii).maps.vols_pm = {};
for kk = 1:nPara
job.subjc(ii).maps.vols_pm{end+1,1} = ...
job.many_sdatas.vols_pm{kk}{ii};
end
end
end
%_______________________________________________________________________