-
Notifications
You must be signed in to change notification settings - Fork 7
/
mirror_warp_calc.sh
executable file
·79 lines (62 loc) · 2.42 KB
/
mirror_warp_calc.sh
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
#!/bin/bash
# Calculate the diffeomorphic warp required to map one hemisphere onto the other.
# Requires an initial reflection of images about the midsagittal plane followed by the
# diffeomorphic warping of the reflected to the unreflected image.
#
# This implementation requires both T1 and T2 contrasts for a multivariate optimization.
#
# AUTHOR : Mike Tyszka
# PLACE : Caltech
# DATES : 2015-07-30 JMT From scratch
# 2016-03-25 JMT Separate calc and apply components of mirror warp
if [ $# -lt 3 ]
then
echo "USAGE : mirror_warp_calc.sh <T1> <T2> <Output Directory>"
exit
fi
T1_orig=$1
T2_orig=$2
out_dir=$3
echo "Original T1w image : ${T1_orig}"
echo "Original T2w image : ${T2_orig}"
echo "Output Directory : ${out_dir}"
# Create output directory safely
echo "Safely creating output directory"
mkdir -p $out_dir
# Copies of original T1 and T2 in output directory
T1=${out_dir}/T1.nii.gz
T2=${out_dir}/T2.nii.gz
# LR mirrored versions of original images
T1_mirror=${out_dir}/T1_mirror.nii.gz
T2_mirror=${out_dir}/T2_mirror.nii.gz
# Final mirror warped versions of original images
T1_mirror_warp=${out_dir}/T1_mirror_warp.nii.gz
T2_mirror_warp=${out_dir}/T2_mirror_warp.nii.gz
# ANTs output prefix
ANTS_prefix=${out_dir}/Mirror
ANTS_warp=WarpImageMultiTransform
mirror_affine=${ANTS_prefix}Affine.txt
mirror_warp=${ANTS_prefix}Warp.nii.gz
# Bivariate ANTs registration options
ANTS_OPTS="-i 30x90x20 -t SyN[0.25] -r Gauss[3,0] --use-Histogram-Matching --number-of-affine-iterations 10000x10000x1000 --MI-option 32x16000"
# Copy T1 and T2 images into output directory
echo " Copying original images to output directory"
cp $T1_orig $T1
cp $T2_orig $T2
chmod +w $T1 $T2
# L-R flip master T1 and T2 templates
echo " Reflecting images about the mid-sagittal plane"
mirror.py -i $T1 -o $T1_mirror
mirror.py -i $T2 -o $T2_mirror
if [ ! -s ${mirror_warp} ]
then
# Warp L-R flipped T1 and T2 onto their unflipped versions
echo " Warping L-R reflected images onto their unreflected versions"
${ANTSPATH}/ANTS 3 -m CC[${T1},${T1_mirror},1,5] -m CC[${T2},${T2_mirror},1,5] ${ANTS_OPTS} -o ${ANTS_prefix}
# Apply mirror warp to L-R flipped T1 and T2
echo " Applying mirror warp"
${ANTSPATH}/WarpImageMultiTransform 3 ${T1_mirror} ${T1_mirror_warp} $mirror_warp $mirror_affine
${ANTSPATH}/WarpImageMultiTransform 3 ${T2_mirror} ${T2_mirror_warp} $mirror_warp $mirror_affine
else
echo " Previous version of warp exists - exiting"
fi