-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspm_smooth
65 lines (63 loc) · 1.58 KB
/
spm_smooth
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
# Setup (with option to run) SPM12 smooth module using shell script
# invoking matlab.
#
# Usage: spm_smooth otherimgfn kernel mbfn rf
#
# otherimgfn - Singular image (to be smoothed), or text filename
# with fullpaths per row per image.
# kernel - 3d smoothing kernel. E.g. 8,8,8
# mbfn - Matlab batch output file name.
# rf - flag to run matlabbatch, 0: no, 1: yes
#
# 20220519 Created by Josh Goh.
# Assign parameters
otherimgfn=${1}
kernel=${2}
mbfn=${3}
rf=${4}
# Call matlab with input script
unset DISPLAY
matlab -nosplash > matlab.out << EOF
settings;
[p n e] = fileparts('${otherimgfn}');
if strcmp(e,'.nii')
ni = niftiinfo('${otherimgfn}');
if length(ni.ImageSize)==4
nvols = ni.ImageSize(4);
for t = 1:nvols,
temp(t).epivol = ['${otherimgfn},' num2str(t)];
end;
other = cellstr(strvcat(temp.epivol));
else
other = '${otherimgfn},1';
end
else
S = textread('${otherimgfn}','%s');
nfiles = size(S,1);
i=1;
for r = 1:nfiles,
ni = niftiinfo(S{r});
if length(ni.ImageSize)==4
nvols = ni.ImageSize(4);
for t = 1:nvols,
temp(i).epivol = [deblank(S{r}) ',' num2str(t)];
i=i+1;
end;
else
temp(i).epivol = '${otherimgfn},1';
i=i+1;
end
end
other = cellstr(strvcat(temp.epivol));
end
matlabbatch{1,1}.spm.spatial.smooth.data = other;
matlabbatch{1,1}.spm.spatial.smooth.fwhm = [${kernel}];
matlabbatch{1,1}.spm.spatial.smooth.dtype = 0;
matlabbatch{1,1}.spm.spatial.smooth.im = 0;
matlabbatch{1,1}.spm.spatial.smooth.prefix = 's';
save('${mbfn}','matlabbatch');
if ${rf},
spm_jobman('run',matlabbatch);
end
exit;
EOF