-
Notifications
You must be signed in to change notification settings - Fork 0
/
midplane.sh
executable file
·76 lines (59 loc) · 1.85 KB
/
midplane.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
#!/bin/bash
usage () {
msg "
Usage: $pn -img 3d-image.nii.gz [options]
Extracts the grid centre plane as a 3D image with xdim = 1 after applying the
transformation optionally given via -dofin. Writes to \$PWD/centreplane.nii.gz
if -out not provided.
Options:
[-dofin mspalign.dof.gz] Transformation to apply before centre plane extraction
[-out mid-sagittal-plane.nii.gz] Output file to receive centre plane
[-ref reference.nii.gz] Image to use as geometry template for output
"
}
ppath=$(realpath "$BASH_SOURCE")
cdir=$(dirname "$ppath")
pn=$(basename "$ppath")
. "$cdir"/common
. "$cdir"/functions
td=$(tempdir)
trap finish EXIT
which help-rst >/dev/null || fatal "MIRTK not on $PATH"
which seg_maths >/dev/null || fatal "NiftySeg not on $PATH"
. $cdir/midplane-function.sh
[[ $# -eq 0 ]] && fatal "Parameter error"
img=
dof=
msp="$PWD"/centreplane.nii.gz
debug=0
label=
while [[ $# -gt 0 ]]
do
case "$1" in
-img) img=$(realpath "$2"); shift;;
-dofin) dof=$(realpath "$2"); shift;;
-out) msp=$(realpath "$2"); shift;;
-ref) ref=$(realpath "$2"); shift;;
-nn) nn=1 ;;
-debug) debug=1 ;;
-label) label="-labels" ;;
--) shift; break;;
-*)
fatal "Parameter error" ;;
*) break;;
esac
shift
done
[[ -n "$img" ]] || fatal "Input image not provided (use -img)"
[[ -e "$img" ]] || fatal "Input image file does not exist"
[[ -z "$dof" ]] && dof=$cdir/neutral.dof.gz
launchdir="$PWD"
cd $td
target=
[[ -n "$ref" ]] && target="-target $ref"
interp="Fast cubic bspline with padding"
[[ $nn ]] && interp="NN"
transform-image "$img" aligned.nii.gz $label $target -dofin "$dof" -interp "$interp"
midplane aligned.nii.gz msp.nii.gz
cp msp.nii.gz "$msp"
exit 0