-
Notifications
You must be signed in to change notification settings - Fork 7
/
resample
executable file
·59 lines (39 loc) · 1.22 KB
/
resample
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
#!/bin/bash
# Resample image isotropically to new voxel size
#
# AUTHOR : Mike Tyszka
# PLACE : Caltech
# DATES : 2016-11-16 JMT From scratch
if [ $# -lt 3 ]; then
echo "USAGE : resample <original image> <resampled image> <isotropic resolution in mm>"
exit
fi
echo "Original image : $1"
echo "Resampled image : $2"
echo "Isotropic resolution : $3 mm"
# FLIRT options
flirt_opts="-init ${FSLDIR}/etc/flirtsch/ident.mat -applyisoxfm ${3} -interp sinc -sincwindow hanning"
# Get image dimensions
ndim=`fslinfo $1 | awk '{ if ($1 == "dim4") { if ($2 > 1) {print "4"} else {print "3"} } }'`
echo "Original image has ${ndim} dimensions"
if [ ${ndim} -eq "3" ]
then
${FSLDIR}/bin/flirt -in $1 -out $2 -ref $1 ${flirt_opts}
elif [ ${ndim} -eq "4" ]
then
tmp_dir="./tmp"
mkdir -p ${tmp_dir}
echo "Splitting 4D volume into $tmp_dir"
fslsplit $1 ${tmp_dir}/vol -t
for vol in ${tmp_dir}/vol*
do
echo " Resampling ${vol}"
out_vol=${vol/.nii.gz/_resamp.nii.gz}
${FSLDIR}/bin/flirt -in ${vol} -out ${out_vol} -ref ${vol} ${flirt_opts}
done
fslmerge -t $2 ${tmp_dir}/*_resamp.nii.gz
rm -rf ${tmp_dir}
else
echo "Unsupported image dimensions : ${ndim}"
exit
fi