-
Notifications
You must be signed in to change notification settings - Fork 2
/
bet-some
executable file
·49 lines (41 loc) · 1.58 KB
/
bet-some
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
#!/usr/bin/env bash
set -euo pipefail
tmpdir=""
trap '[ -n "$tmpdir" -a -d "$tmpdir" ] && rm -r $tmpdir' EXIT SIGINT
[ -v "SCALE" ] || SCALE=200%
imageviewer=${IMAGEVIEWER:-feh}
usage(){
local exit=0
[ $# -gt 0 ] && echo "ERROR: $*" && exit=1
cat<<HD
$0 niftifile [frac1 frac2 ....]
$0 -help = this help
run a bunch of bets and show the results in $imageviewer (\$IMAGEVIEWER)
defaults to frac .1 to .9 by 1
SCALE=100% $0 nifile .5 # undo default 200% scaling
IMAGEVIEWER=: $0 nifile .5 # dont open an imageviewer after bets
HD
exit $exit
}
[ $# -eq 0 ] && usage "need at least a nifti image"
[[ "$1" =~ ^-h*|^-useage ]] && usage
! command -v bet >/dev/null && warn "no 'bet' command! install fsl" && exit 1
! command -v $imageviewer >/dev/null && warn "no image viewer '$imageviewer'. set IMAGEVIEWER. IMAGEVIEWER=':' to ignore" && exit 1
img="$1"; shift
[ $# -eq 0 ] && frac=($(seq .1 .1 .9)) || frac=("$@")
tmpdir=$(mktemp -d /tmp/bet-some-XXX)
echo "# writing to '$tmpdir' (removed when '$imageviewer' closes)"
for frac in ${frac[@]}; do
echo -n "$frac ... "
out=$tmpdir/bet-$frac.nii.gz
sliceout=${out/nii.gz/png}
bet $img $out -f $frac
# with the unnamed pipe, we dont wait for convert to finish.
# 'all.png' will miss last one. easiest if in two steps
# slicer -a >(convert -scale $SCALE - -background white label:$frac -gravity center -append $sliceout) $out $img
slicer -a $sliceout $out $img
convert -scale $SCALE $sliceout -background white label:$frac -gravity center -append $sliceout
done
echo
convert -append $tmpdir/*.png $tmpdir/all.png
$imageviewer $tmpdir/all.png