-
Notifications
You must be signed in to change notification settings - Fork 0
/
acqparams_maker.sh
executable file
·84 lines (76 loc) · 2.32 KB
/
acqparams_maker.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
80
81
82
83
84
#!/bin/bash
# This script is to make acqparams.txt using json file made by dcm2niix.
# DWIs of reversed phase encoding directions are required.
# Usage: acqparams_maker.sh dwi.json reversed_encoding_dwi.json
# (dwi is always larger than or equal size to reversed_encoding_dwi)
# Note: Here the coordinate system is assumed to be RAS.
# So phase encoding direction is as follows:
# i LR
# i- RL
# j PA
# j- AP
# k IS
# k- SI
# In most cases of dwi image this is correct, but you may want to check the image with your own eyes.
if [[ -z $1 ]]; then
echo "Please specify json.file. Usage: acqparams_maker.sh yourjsonfile.jsons"
exit
elif [[ ! -f $1 ]]; then
echo "This file does not exist. Please check the path."
exit
else :
fi
if [[ -z $2 ]]; then
echo "Please specify json.file. Usage: acqparams_maker.sh yourjsonfile.json"
exit
elif [[ ! -f $2 ]]; then
echo "This file does not exist. Please check the path."
exit
else :
fi
TRT1=$(cat $1 | grep TotalReadoutTime | cut -d: -f2 | tr -d ',')
PED1=$(cat $1 | grep \"PhaseEncodingDirection\"| cut -d: -f2 | tr -d '," ')
TRT2=$(cat $2 | grep TotalReadoutTime | cut -d: -f2 | tr -d ',')
PED2=$(cat $2 | grep \"PhaseEncodingDirection\"| cut -d: -f2 | tr -d '," ')
echo "Phase encoding direction is $PED1 and $PED2."
read -p "How many b0s from $1 do you want to use for topup? > " num1
read -p "How many b0s from $2 do you want to use for topup? > " num2
case "$PED1" in
"i")
the_1st_row="1 0 0 $TRT1"
the_2nd_row="-1 0 0 $TRT2"
;;
"i-")
the_1st_row="-1 0 0 $TRT1"
the_2nd_row="1 0 0 $TRT2"
;;
"j")
the_1st_row="0 1 0 $TRT1"
the_2nd_row="0 -1 0 $TRT2"
;;
"j-")
the_1st_row="0 -1 0 $TRT1"
the_2nd_row="0 1 0 $TRT2"
;;
"k")
the_1st_row="0 0 1 $TRT1"
the_2nd_row="0 0 -1 $TRT2"
;;
"k-")
the_1st_row="0 0 -1 $TRT1"
the_2nd_row="0 0 1 $TRT2"
;;
*)
echo "Unable to detect phase encoding direction."
exit
;;
esac
for i in $(seq $num1); do
echo $the_1st_row >> acqparams.txt
done
for j in $(seq $num2); do
echo $the_2nd_row >> acqparams.txt
done
echo "Successful."
echo "Note that when you will merge b0s for topup --imain, \
the order of files should be $1 first and $2 second."