Skip to content
Snippets Groups Projects
Commit e43549b6 authored by Mark Jenkinson's avatar Mark Jenkinson
Browse files

Added an option -m for saving the matrix directly to a file, and also used...

Added an option -m for saving the matrix directly to a file, and also used tmpnam to avoid clashing outputs for temporary *_nii.mat file
parent 148f2211
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# reorientation script # reorientation script
# #
# Matthew Webster # Matthew Webster and Mark Jenkinson
# FMRIB Image Analysis Group # FMRIB Image Analysis Group
# #
# Copyright (C) 2012 University of Oxford # Copyright (C) 2012 University of Oxford
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# SHCOPYRIGHT # SHCOPYRIGHT
if [ $# -lt 1 ] ; then if [ $# -lt 1 ] ; then
echo "Usage: `basename $0` <input_image> [output_image]" echo "Usage: `basename $0` [-m <matrix file>] <input_image> [output_image]"
echo " " echo " "
echo "`basename $0` is a tool for reorienting the image to match the" echo "`basename $0` is a tool for reorienting the image to match the"
echo "approximate orientation of the standard template images (MNI152)." echo "approximate orientation of the standard template images (MNI152)."
...@@ -21,12 +21,19 @@ if [ $# -lt 1 ] ; then ...@@ -21,12 +21,19 @@ if [ $# -lt 1 ] ; then
echo "assumes the labels are correct - if not, fix that before using this." echo "assumes the labels are correct - if not, fix that before using this."
echo "If the output name is not specified the equivalent transformation" echo "If the output name is not specified the equivalent transformation"
echo " matrix is written to the standard output" echo " matrix is written to the standard output"
echo "If the option -m is given, with an accompanying filename, then the"
echo " transformation matrix is written to this file instead"
echo " " echo " "
exit 1 exit 1
fi fi
if [ $1 = -m ] ; then
matfn=$2
shift 2
fi
img=`$FSLDIR/bin/remove_ext $1`; img=`$FSLDIR/bin/remove_ext $1`;
outimg=$2; outimg=$2;
tmpfn=`$FSLDIR/bin/tmpnam`
if [ `$FSLDIR/bin/imtest $img` = 0 ] ; then if [ `$FSLDIR/bin/imtest $img` = 0 ] ; then
echo "ERROR: Could not find image $1" 1>&2 echo "ERROR: Could not find image $1" 1>&2
...@@ -47,15 +54,23 @@ pattern=sto_xyz ...@@ -47,15 +54,23 @@ pattern=sto_xyz
if [ $scode = 0 ] ; then if [ $scode = 0 ] ; then
pattern=qto_xyz pattern=qto_xyz
fi fi
$FSLDIR/bin/fslhd $img | grep $pattern | awk '{ print $2 " " $3 " " $4 " " $5 }' > ${outimg}_nii.mat $FSLDIR/bin/fslhd $img | grep $pattern | awk '{ print $2 " " $3 " " $4 " " $5 }' > ${tmpfn}_nii.mat
det=`$FSLDIR/bin/avscale ${outimg}_nii.mat | grep Determinant | awk '{ print $3 }'`; det=`$FSLDIR/bin/avscale ${tmpfn}_nii.mat | grep Determinant | awk '{ print $3 }'`;
if [ X`echo "if ( $det < 0 ) { 1 }" | bc -l` = X1 ] ; then if [ X`echo "if ( $det < 0 ) { 1 }" | bc -l` = X1 ] ; then
# radiological case (negative determinant) # radiological case (negative determinant)
$FSLDIR/bin/fslswapdim $img RL PA IS $outimg LeftRight=RL
else
LeftRight=LR
fi
if [ X$matfn = X ] ; then
$FSLDIR/bin/fslswapdim $img $LeftRight PA IS $outimg
else else
$FSLDIR/bin/fslswapdim $img LR PA IS $outimg $FSLDIR/bin/fslswapdim $img $LeftRight PA IS > $matfn
if [ X$outimg != X ] ; then
$FSLDIR/bin/fslswapdim $img $LeftRight PA IS $outimg
fi
fi fi
# clean up # clean up
rm -f ${outimg}_nii.mat rm -f ${tmpfn}_nii.mat ${tmpfn}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment