/
mkniigz.sh
executable file
·50 lines (41 loc) · 1.23 KB
/
mkniigz.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
#!/bin/bash
# Converts .nii/.img/.hdr to .nii.gz and deletes original file.
# Written by Andreas Heckel
# University of Heidelberg
# heckelandreas@googlemail.com
# https://github.com/ahheckel
# 28/10/2014
trap 'echo "$0 : An ERROR has occured."' ERR
set -e
Usage() {
echo ""
echo "Usage: `basename $0` <input4D> [<nii.gz-output4D-basename>]"
echo "Example: `basename $0` input.hdr output.nii.gz"
echo " `basename $0` input.hdr input"
echo " `basename $0` input.img"
echo " `basename $0` input.nii"
echo ""
exit 1
}
[ "$1" = "" ] && Usage
# define vars
input="$1" ; in_ext=${input##*.}
input=`remove_ext "$1"`
output=`remove_ext "$2"`
if [ x"$output" = "x" ] ; then output="$input" ; fi
# check
if [ $(imtest $input) -eq 0 ] ; then echo "`basename $0` : ERROR : cannot read '$input' - exiting." ; exit ; fi
# execute
cmd="fslmaths $input ${output}.nii.gz"
echo "`basename $0` : $cmd" ; $cmd
if [ "${in_ext}" = "hdr" -o "${in_ext}" = "img" ] ; then
cmd="rm -f ${input}.hdr"
echo "`basename $0` : $cmd" ; $cmd
cmd="rm -f ${input}.img"
echo "`basename $0` : $cmd" ; $cmd
else
cmd="rm -f ${input}.${in_ext}"
echo "`basename $0` : $cmd" ; $cmd
fi
# done
echo "`basename $0` : done."