/ fixto1809c
fixto1809c
 1  #!/usr/bin/env bash
 2  # make .18_09c.nii.gz from input file
 3  # optionally, if given second argument "mask", will use NN interp instead of sinc
 4  fixto1809c() { 
 5    [ $# -lt 1 ] && echo "usage: $FUNCNAME to_correct.nii.gz [-mask] [-mkbad] [-out newfile.nii.gz]" && return 1
 6  
 7    local reffolder="/opt/ni_tools/standard/mni_icbm152_nlin_asym_09c"
 8    local newname="18_09c"
 9    local mask=""
10    local output="";
11  
12    local input=$1; shift
13    while [ $# -ne 0 ]; do
14       case $1 in
15          -mask) mask=1; shift;;
16          -out) shift; output=$1; shift;;
17          -mkbad) 
18             reffolder="/opt/ni_tools/standard_old/mni_icbm152_nlin_asym_09c"
19             newname="bad_09c"
20             shift;;
21           *) echo "unkown argument $1! no args for help"; return 1;;
22      esac
23    done
24  
25    [ $# -eq 2 ] && [ "$2" != "ismask" ] && echo "only valid second argument is 'ismask', you gave $2" && return 1
26  
27    # output name cannot be changed, requires input be .nii.gz
28    [ -z "$output" ] && output="${input/.nii.gz/.$newname.nii.gz}"
29    #output="$(dirname $input)/$(basename "$input" .nii.gz).18_09c.nii.gz"
30  
31    # checks
32    [ -z "$input" -o ! -r "$input" ] && echo "$FUNCNAME needs nifti to warp. given '$input'" >&2 && return 1
33    ! 3dinfo -space $input | grep -iq mni && echo "$input is not in mni space!" >&2 && return 1
34  
35    dim=$(3dinfo -adj $input|sed 's/0\+$//;s/\.$//')
36    [ $dim != "1" ] && dim=_${dim}mm
37  
38    local ref=$reffolder/mni_icbm152_t1_tal_nlin_asym_09c${dim}.nii 
39    # /opt/ni_tools/standard/09cFix/gen_mats.bash
40    local mat=/opt/ni_tools/standard_old/09cFix/2mm_luna_to_fixed.mat 
41    # file is identity:
42    # 1  0  0  0  
43    # 0  1  0  0  
44    # 0  0  1  0  
45    # 0  0  0  1  
46  
47    [ ! -r $ref -o ! -r $mat ] && echo "$FUNCNAME cannot find ref or mat ($ref $mat)" >&2 && return 1
48    [ -z "$REDOWARP" -a -r "$output" ] && echo "have $output" >&2 && return 0
49    echo "creating $output ($dim)"
50    cmd="applyxfm4D '$input'  $ref '$output'  $mat -singlematrix" # default to sinc
51    [ -n "$mask" ] && cmd="flirt -ref '$ref' -in '$input' -applyxfm -init '$mat' -out '$output' -interp nearestneighbour"
52    if command -v rel >/dev/null; then
53       rel "$cmd # $(pwd)" c
54    else
55       echo "$cmd # $(pwd)"
56    fi
57    eval "$cmd" && 3dNotes -h "[$FUNCNAME] $cmd" "$output"
58  }
59  
60  if [ "$(basename $0)" == fixto1809c ]; then
61     fixto1809c $@
62  fi
63  # vim: set tabstop=7: