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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/bin/sh
##
## Copyright 2012, 2014 SRI International
##
## Copyright 2012 Torsten Rohlfing
##
## This file is part of the Computational Morphometry Toolkit.
##
## http://www.nitrc.org/projects/cmtk/
##
## The Computational Morphometry Toolkit is free software: you can
## redistribute it and/or modify it under the terms of the GNU General Public
## License as published by the Free Software Foundation, either version 3 of
## the License, or (at your option) any later version.
##
## The Computational Morphometry Toolkit is distributed in the hope that it
## will be useful, but WITHOUT ANY WARRANTY; without even the implied
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with the Computational Morphometry Toolkit. If not, see
## <http://www.gnu.org/licenses/>.
##
## $Revision: 5378 $
##
## $LastChangedDate: 2015-01-17 11:31:55 -0800 (Sat, 17 Jan 2015) $
##
## $LastChangedBy: torstenrohlfing $
##
export CMTK_BINARY_DIR=${CMTK_BINARY_DIR:-@CMTK_BINARY_DIR_CONFIG@}
# Get the cmtk_functions.sh script from the scripts/ directory in the CMTK source tree
. ${CMTK_BINARY_DIR}/cmtk_functions.sh
# Check for command line arguments, print help if none given
if test $# -lt 3; then
echo "Reformat all floating images previously aligned by one of CMTK's groupwise registration tools."
echo
echo "USAGE: $0 [OPTIONS] groupwiseXform templateGrid outputPathPattern [XFORMS ...]"
exit 2
fi
# put all arguments starting with "-" into reformat options
reformatOptions=""
while expr "$1" : ^- >/dev/null; do
reformatOptions="${reformatOptions}$1 "
shift
done
# first non-option argument is groupwise xform
groupwiseXform=$1
if [ ! -f ${groupwiseXform} ]; then
groupwiseXform=${groupwiseXform}.gz
if [ ! -f ${groupwiseXform} ]; then
echo "ERROR: could not find groupwise transformation $1"
exit 1
fi
fi
# second argument is template grid path
templateGrid=$2
if ! ${CMTK_BINARY_DIR}/describe ${templateGrid} > /dev/null; then
echo "ERROR: template grid ${templateGrid} is not a valid image."
exit 1
fi
# third argument is output pattern
outPattern=$3
# everything else is optional xforms to be added before the groupwise alignment
shift 3
reformatXforms="$*"
make_output_path()
{
local target=$1
local pattern=$2
local base=`basename $target | sed 's/\..*//g'`
local dir=`dirname $target`
local idx=1
while [ "${base}" != "" ]; do
pattern=`eval "echo $pattern | sed 's/%${idx}/${base}/g'"`
base=`basename $dir | sed 's/\.,*//g'`
dir=`dirname $dir`
$((idx=idx+1))
done
echo ${pattern}
}
process_target()
{
local target=$1
local tmp=`mktemp`
echo "! TYPEDSTREAM 1.1" > ${tmp}
while IFS="" read line; do
if expr "${line}" : ^\} >/dev/null; then
break;
fi
echo "${line}" >> ${tmp}
done
echo "}" >> ${tmp}
outputPath=`make_output_path ${target} ${outPattern}`
if [ "${outputPath}" != "" ]; then
${CMTK_BINARY_DIR}/reformatx ${reformatOptions} --floating ${target} --outfile ${outputPath} ${templateGrid} ${tmp} ${reformatXforms}
fi
rm -rf ${tmp}
}
parse_xform_file()
{
while read line; do
if expr "${line}" : "target" >/dev/null; then
target=`echo ${line} | sed 's/target \"//g; s/\".*//g'`
process_target ${target}
fi
done
}
gzip -cdf ${groupwiseXform} | parse_xform_file
|