#! /bin/csh -f # # inorm3 # # Original Author: Doug Greve # CVS Revision Info: # $Author: greve $ # $Date: 2009/10/08 23:19:50 $ # $Revision: 1.2 $ # # Copyright (C) 2002-2007, # The General Hospital Corporation (Boston, MA). # All rights reserved. # # Distribution, usage and copying of this software is covered under the # terms found in the License Agreement file named 'COPYING' found in the # FreeSurfer source code root directory, and duplicated here: # https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense # # General inquiries: freesurfer@nmr.mgh.harvard.edu # Bug reports: analysis-bugs@nmr.mgh.harvard.edu # set VERSION = '$Id: inorm3,v 1.2 2009/10/08 23:19:50 greve Exp $'; set cmdargs = ($argv); set instem = (); set meanvalfile = (); set maskstem = (); set nskip = 0; set cleanup = 1; set PrintHelp = 0; if($#argv == 0) goto usage_exit; set n = `echo $argv | grep -e -help | wc -l` if($n != 0) then set PrintHelp = 1; goto usage_exit; exit 1; endif goto parse_args; parse_args_return: goto check_params; check_params_return: set instem = `getfullpath $instem`; set invol = `stem2fname $instem`; if($status) then echo "$invol" exit 1; endif set maskstem = `getfullpath $maskstem`; set maskvol = `stem2fname $maskstem`; if($status) then echo "$maskvol" exit 1; endif set meanvalfile = `getfullpath $meanvalfile`; set outdir = `dirname $meanvalfile` set tmpdir = $outdir/tmp.inorm3.$$ mkdir -p $tmpdir set tmpvol = $tmpdir/f.nii set cmd = (mri_convert $invol $tmpvol --nskip $nskip) echo $cmd $cmd if($status) exit 1; set meanvol = $tmpdir/f.mean.nii mri_concat $tmpvol --mean --o $meanvol if($status) exit 1; rm -f $tmpvol set segsum = $tmpdir/f.mean.sum mri_segstats --i $meanvol --seg $maskvol --id 1 --sum $segsum if($status) exit 1; set meanval = `grep -v \# $segsum | awk '{print $6}'` echo $meanval | tee $meanvalfile if($cleanup) rm -r $tmpdir echo "inorm3 Done" exit 0; ############################################### ############--------------################## parse_args: set cmdline = "$argv"; while( $#argv != 0 ) set flag = $argv[1]; shift; switch($flag) case "-i": if($#argv < 1) goto arg1err; set instem = $argv[1]; shift; breaksw case "-m": case "-mask": if($#argv < 1) goto arg1err; set maskstem = $argv[1]; shift; breaksw case "-meanval": if($#argv < 1) goto arg1err; set meanvalfile = $argv[1]; shift; breaksw case "-nskip": if($#argv < 1) goto arg1err; set nskip = $argv[1]; shift; breaksw case "-no-cleanup": set cleanup = 0; breaksw case "-debug": set verbose = 1; set echo = 1; breaksw default: echo ERROR: Flag $flag unrecognized. echo $cmdline exit 1 breaksw endsw end goto parse_args_return; ############--------------################## ############--------------################## check_params: if($#instem == 0) then echo "ERROR: need input" exit 1; endif if($#meanvalfile == 0) set meanvalfile = $instem.meanval if($#maskstem == 0) then echo "ERROR: need mask" exit 1; endif goto check_params_return; ############--------------################## ############--------------################## arg1err: echo "ERROR: flag $flag requires one argument" exit 1 ############--------------################## ############--------------################## usage_exit: echo "" echo "USAGE: inorm3" echo "" echo " -i instem " echo "" echo " -m maskstem " echo " -meanval meanvalfile : default is instem.meanval " echo " " echo " -nskip N : do not use first N TRs in computing meanval" echo " " echo " -debug" echo " -version : print version and exit" echo " -help : print help and exit" echo "" if(! $PrintHelp) exit 1; echo $VERSION echo "------------------------------------------------------------" cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0; if($1 == "BEGINHELP") prt = 1 }' echo "------------------------------------------------------------" exit 1; #---- Everything below here is printed out as part of help -----# BEGINHELP Computes the in-brain mean value of the given input volume. The result is stored in instem.meanval unless otherwise specified. "In-brain" is defined by the mask. Autodetects format from the input stem. This is the same as inorm2 but requires a mask and does NOT run matlab.