Hi
This should be quiet a simple thing to script, you need two fsl
functions for this:
1. 'overlay' - to create a data file with the statistics rendered on it
2. 'slicer' - to extract a specific slice from this rendered 3D volume
If you want to put all subjects into a single image file, you can
combine slices with pngappend, the name could be 'transformed' to a png
file as well and appended to the subject's slice.
I attached two slightly overkill BASH script that do all this. Maybe it
can serve you as a pointer. However, I can't guarantee, that these
script is working correctly, so take care using it ;-)
good luck,
wolf
On 13/07/11 13:02, Cris Lanting wrote:
> Dear list,
>
> I've got a simple question and I'm quite sure someone already invented
> this particular type of wheel...
> To check the consistency of activation/component maps across subjects
> (or between groups) I' like to display a single slice per subject with
> a certain overlay (t, F, Z maps
> or component map if I were to do ICA analyses). Does anyone have this
> type of script (bash?) or is willing to provide some pointers? (I.e.,
> is there a simple way to extract one slice rather than one volume as
> with fslsplit?)
>
> Cheers,
> Cris Lanting
#!/bin/bash
#
Usage() {
cat << EOF
Usage: vol_slicer <bg_img> [OPTIONS]
OPTIONS:
-x -y -z specify set of slices to save as image (e.g. -z "2 4 6 8 10")
numbers > 1 specify slicenumbers, numbers < 1 specify proportions.
-stat <flnm> statistical map
-trans transparent colors
-pxl number of pixels seperating two images (default:10)
-thick increase width of slice line
-neg render also the negative stat map
-noside do not show right side label
-mm print slice distance from center voxel
-cx for single voxel display overlay slice selections on stat maps
-s <sclfctr> scaling factor
-bgint <min max> intensity range for the background image
-statrng <min max> scaling theshold
-out <outname> filename for output data
-keep do not delete temporary files
###########################################################
## (c) wolf zinke (2008) - part of the MaFIA toolbox ##
## for comments and questions: [log in to unmask] ##
###########################################################
EOF
exit 1
}
#----------------------------------------------------------------------#
if [ $# -lt 1 ]; then
Usage
else
bg_img=`remove_ext $1`;
shift
fi
#----------------------------------------------------------------------#
outnm="${bg_img}_sliceselection.png"
bgint=`fslstats $bg_img -r`
smint="3 10"
scl=1
pxl=10
sdlbl=""
trans=0
do_keep=0
do_neg=0
do_thick=0
tmpdir=`tmpnam tmpPSC`
xstr=""
ystr=""
zstr=""
slcwdth=1
statmap=""
getsmint=1
doMM=0
doCX=0
SglVXL=1
rm $tmpdir
#----------------------------------------------------------------------#
# get options
while [ $# -gt 0 ] ;
do
case $1 in
-out) outnm=$2
shift 2
;;
-stat) statmap=`remove_ext $2`
shift 2
;;
-x) xstr="$1 '$2'"
xslc="$2"
shift 2
;;
-y) ystr="$1 '$2'"
yslc="$2"
shift 2
;;
-z) zstr="$1 '$2'"
zslc="$2"
shift 2
;;
-s) scl=$2
shift 2
;;
-mm) doMM=1
shift
;;
-cx) doCX=1
shift
;;
-bgint) bgint="$2 $3"
shift 3
;;
-statrng) smint="$2 $3"
getsmint=0
shift 3
;;
-thick) do_thick=1
slcwdth=3
shift
;;
-trans) trans=1
shift
;;
-noside) sdlbl="-u"
shift
;;
-neg) do_neg=1
shift
;;
-pxl) pxl=$2
shift 2
;;
-keep) do_keep=1
shift
;;
-*) echo "Wrong option: <$1>"
echo ""
Usage
;;
*) break
;;
esac
done
mkdir $tmpdir;
slcfl=`echo $outnm | sed -e 's/.png/.slc/g'`
echo "bgimg: $bg_img" > $slcfl
slcsc=`echo "$scl / 2" | bc -l`
if [ $(($doCX+$do_neg)) -eq 2 ]
then
echo "WARNING: Can not do crosshair overlay if -neg option is used!"
doCX=0
fi
#----------------------------------------------------------------------#
numX=0
numY=0
numZ=0
# x
if [ "$xstr" ]
then
for cslc in $xslc
do
numX=$(($numX+1))
done
fi
if [ ! $numX -eq 1 ]
then
SglVXL=0
fi
# y
if [ "$ystr" ]
then
for cslc in $yslc
do
numY=$(($numY+1))
done
fi
if [ ! $numY -eq 1 ]
then
SglVXL=0
fi
# z
if [ "$zstr" ]
then
for cslc in $zslc
do
numZ=$(($numZ+1))
done
fi
if [ ! $numZ -eq 1 ]
then
SglVXL=0
fi
#----------------------------------------------------------------------#
# get the slice representation
fslmaths $bg_img -mul 0 -add 1 $tmpdir/all_slices -odt char
Xsz=`fslval $bg_img dim1`
Ysz=`fslval $bg_img dim2`
Zsz=`fslval $bg_img dim3`
png_str=""
set_cnt=0
if [ $SglVXL -eq 1 ]
then
fslmaths $bg_img -mul 0 -add 1 $tmpdir/allone -odt char
fslmaths $tmpdir/all_slices -roi 0 $Xsz $yslc 1 $zslc 1 0 1 $tmpdir/xslcsel
fslmaths $tmpdir/all_slices -roi $xslc 1 0 $Ysz $zslc 1 0 1 $tmpdir/yslcsel
fslmaths $tmpdir/all_slices -roi $xslc 1 $yslc 1 0 $Zsz 0 1 $tmpdir/zslcsel
fslmaths $tmpdir/xslcsel -add $tmpdir/yslcsel -add $tmpdir/zslcsel $tmpdir/slcsel
overlay 0 1 $bg_img $bgint $tmpdir/slcsel 1 4 $tmpdir/slc_vol
slicer $tmpdir/slc_vol -s $slcsc $sdlbl -x -$xslc $tmpdir/selX.png -y -$yslc $tmpdir/selY.png -z -$zslc $tmpdir/selZ.png
fi
#----------------------------------------------------------------------#
# prepare overlay image
if [ "$statmap" ]
then
if [ $getsmint -eq 1 ]
then
if [ $do_neg -eq 1 ]
then
smint=`fslstats $statmap -a -r`
else
smint=`fslstats $statmap -l 0 -r`
fi
fi
statstr=""
cnt=0
for cstat in $statmap
do
cnt=$(($cnt+1))
statstr="$statstr $cstat $smint"
done
#echo "$statstr"
if [ $do_neg -eq 1 ]
then
if [ $cnt -gt 1 ]
then
echo ""
echo "WARNING: negative map could only be used with one statistical map as input"
echo ""
else
fslmaths $statmap -mul -1 $tmpdir/negmap
statstr="$statstr $tmpdir/negmap $smint"
fi
fi
if [ $(($doCX+$cnt)) -gt 2 ]
then
echo "WARNING: Can not do crosshair overlay if more stat maps are used!"
doCX=0
fi
if [ $doCX -eq 1 ]
then
overlay $trans 1 $bg_img $bgint $statstr $tmpdir/slcsel 1 4 $tmpdir/curr_img
else
overlay $trans 1 $bg_img $bgint $statstr $tmpdir/curr_img
fi
echo "statmap: $statmap" >> $slcfl
echo "statrange: $smint " >> $slcfl
else
imcp $bg_img $tmpdir/curr_img
fi
#----------------------------------------------------------------------#
# X
if [ $numX -gt 0 ]
then
origMM=`fslhd $bg_img | grep sto_xyz:1 | awk ' { if($5>=0) { print $5} else {print $5*-1 }}'`
vxlres=`fslval $bg_img pixdim1`
origVXL=` echo "$origMM / $vxlres" | bc -l | awk ' { printf "%.0f\n", $0 } '`
xstr="X slices [mm]:"
# xslices=""
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/xslcsel -odt char
fi
cnt=0
for cslc in $xslc
do
if [ $cslc -gt $Xsz ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in X dimension"
echo ""
rm -r $tmpdir
exit
fi
slicer $tmpdir/curr_img -s $scl -u -x -$cslc $tmpdir/X_${cslc}.png
# xslices="$xslices $tmpdir/X_${cslc}.png"
cvxlMM=`echo "($origVXL - $cslc) * $vxlres" | bc -l | awk ' { printf "%6.2f\n", $0 } ' `
mmX=$cvxlMM
xstr=`echo "$xstr $cvxlMM;"`
if [ $doMM -eq 1 ]
then
eqn2gif -text "$cvxlMM" $tmpdir/slcMM.gif 2 > /dev/null 2>&1
# convert $tmpdir/slcMM.gif $tmpdir/slcMM.png
pngappend $tmpdir/slcMM.gif - 0 $tmpdir/X_${cslc}.png $tmpdir/X_${cslc}.png
fi
cnt=$(($cnt+1))
if [ $cnt -eq 1 ]
then
cp $tmpdir/X_${cslc}.png $tmpdir/Xset.png
else
pngappend $tmpdir/Xset.png + $pxl $tmpdir/X_${cslc}.png $tmpdir/Xset.png
fi
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc-1))
fi
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -roi $cslc $slcwdth 0 $Ysz 0 $Zsz 0 1 $tmpdir/tmp_slcsel
fslmaths $tmpdir/xslcsel -add $tmpdir/tmp_slcsel $tmpdir/xslcsel
fi
done
echo "$xstr"
echo "$xstr" >> $slcfl
if [ $SglVXL -eq 0 ]
then
overlay 0 1 $bg_img $bgint $tmpdir/xslcsel 1 4 $tmpdir/Xslc_vol
slicer $tmpdir/Xslc_vol -s $slcsc $sdlbl -y 0.5 $tmpdir/XselY.png -z 0.6 $tmpdir/XselZ.png
pngappend $tmpdir/XselY.png - 0 $tmpdir/XselZ.png $tmpdir/Xsel.png
pngappend $tmpdir/Xsel.png + $pxl $tmpdir/Xset.png $tmpdir/Xset.png
fi
png_str="$png_str $tmpdir/Xset.png"
set_cnt=$(($set_cnt+1))
fi
# Y
if [ $numY -gt 0 ]
then
origMM=`fslhd $bg_img | grep sto_xyz:2 | awk ' { if($5>=0) { print $5} else {print $5*-1 }}'`
vxlres=`fslval $bg_img pixdim2`
origVXL=` echo "$origMM / $vxlres" | bc -l | awk ' { printf "%.0f\n", $0 } '`
ystr="Y slices [mm]:"
# yslices=""
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/yslcsel -odt char
fi
cnt=0
for cslc in $yslc
do
if [ $cslc -gt $Ysz ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in Y dimension"
echo ""
rm -r $tmpdir
exit
fi
slicer $tmpdir/curr_img -s $scl -u -y -$cslc $tmpdir/Y_${cslc}.png
# yslices="$yslices $tmpdir/Y_${cslc}.png"
cvxlMM=`echo "($cslc - $origVXL) * $vxlres" | bc -l | awk ' { printf "%6.2f\n", $0 } ' `
mmY=$cvxlMM
ystr=`echo "$ystr $cvxlMM;"`
if [ $doMM -eq 1 ]
then
eqn2gif -text "$cvxlMM" $tmpdir/slcMM.gif 2 > /dev/null 2>&1
# convert $tmpdir/slcMM.gif $tmpdir/slcMM.png
pngappend $tmpdir/slcMM.gif - 0 $tmpdir/Y_${cslc}.png $tmpdir/Y_${cslc}.png
fi
cnt=$(($cnt+1))
if [ $cnt -eq 1 ]
then
cp $tmpdir/Y_${cslc}.png $tmpdir/Yset.png
else
pngappend $tmpdir/Yset.png + $pxl $tmpdir/Y_${cslc}.png $tmpdir/Yset.png
fi
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc-1))
fi
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -roi 0 $Xsz $cslc $slcwdth 0 $Zsz 0 1 $tmpdir/tmp_slcsel
fslmaths $tmpdir/yslcsel -add $tmpdir/tmp_slcsel $tmpdir/yslcsel
fi
done
echo "$ystr"
echo "$ystr" >> $slcfl
if [ $SglVXL -eq 0 ]
then
overlay 0 1 $bg_img $bgint $tmpdir/yslcsel 1 4 $tmpdir/Yslc_vol
slicer $tmpdir/Yslc_vol -s $slcsc $sdlbl -x 0.4 $tmpdir/YselX.png -z 0.6 $tmpdir/YselZ.png
pngappend $tmpdir/YselX.png - 0 $tmpdir/YselZ.png $tmpdir/Ysel.png
pngappend $tmpdir/Ysel.png + $pxl $tmpdir/Yset.png $tmpdir/Yset.png
fi
png_str="$png_str $tmpdir/Yset.png"
set_cnt=$(($set_cnt+1))
fi
# Z
if [ $numZ -gt 0 ]
then
origMM=`fslhd $bg_img | grep sto_xyz:3 | awk ' { if($5>=0) { print $5} else {print $5*-1 }}'`
vxlres=`fslval $bg_img pixdim3`
origVXL=` echo "$origMM / $vxlres" | bc -l | awk ' { printf "%.0f\n", $0 } '`
zstr="Z slices [mm]:"
# zslices=""
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/zslcsel -odt char
fi
cnt=0
for cslc in $zslc
do
if [ $cslc -gt $Zsz ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in Z dimension"
echo ""
rm -r $tmpdir
exit
fi
slicer $tmpdir/curr_img -s $scl -u -z -$cslc $tmpdir/Z_${cslc}.png
# zslices="$zslices $tmpdir/Z_${cslc}.png"
cvxlMM=`echo "($cslc - $origVXL) * $vxlres" | bc -l | awk ' { printf "%6.2f\n", $0 } ' `
mmZ=$cvxlMM
zstr=`echo "$zstr $cvxlMM;"`
if [ $doMM -eq 1 ]
then
eqn2gif -text "$cvxlMM" $tmpdir/slcMM.gif 2 > /dev/null 2>&1
# convert $tmpdir/slcMM.gif $tmpdir/slcMM.png
pngappend $tmpdir/slcMM.gif - 0 $tmpdir/Z_${cslc}.png $tmpdir/Z_${cslc}.png
fi
cnt=$(($cnt+1))
if [ $cnt -eq 1 ]
then
cp $tmpdir/Z_${cslc}.png $tmpdir/Zset.png
else
pngappend $tmpdir/Zset.png + $pxl $tmpdir/Z_${cslc}.png $tmpdir/Zset.png
fi
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc-1))
fi
if [ $SglVXL -eq 0 ]
then
fslmaths $tmpdir/all_slices -roi 0 $Xsz 0 $Ysz $cslc $slcwdth 0 1 $tmpdir/tmp_slcsel
fslmaths $tmpdir/zslcsel -add $tmpdir/tmp_slcsel $tmpdir/zslcsel
fi
done
echo "$zstr"
echo "$zstr" >> $slcfl
if [ $SglVXL -eq 0 ]
then
overlay 0 1 $bg_img $bgint $tmpdir/zslcsel 1 4 $tmpdir/Zslc_vol
slicer $tmpdir/Zslc_vol -s $slcsc $sdlbl -x 0.4 $tmpdir/ZselX.png -y 0.5 $tmpdir/ZselY.png
pngappend $tmpdir/ZselX.png - 0 $tmpdir/ZselY.png $tmpdir/Zsel.png
pngappend $tmpdir/Zsel.png + $pxl $tmpdir/Zset.png $tmpdir/Zset.png
fi
png_str="$png_str $tmpdir/Zset.png"
set_cnt=$(($set_cnt+1))
fi
#----------------------------------------------------------------------#
if [ "$statmap" ]
then
declare -a zthr=($smint)
eqn2gif -text "${zthr[0]}" $tmpdir/lowZ.gif 2 > /dev/null 2>&1
eqn2gif -text "${zthr[1]}" $tmpdir/high.gif 2 > /dev/null 2>&1
if [ $do_neg -eq 1 ]
then
eqn2gif -text "-${zthr[0]}" $tmpdir/nlowZ.gif 2 > /dev/null 2>&1
eqn2gif -text "-${zthr[1]}" $tmpdir/nhigh.gif 2 > /dev/null 2>&1
pngappend $tmpdir/nhigh.gif + 5 $FSLDIR/etc/luts/ramp2.gif + 10 $tmpdir/nlowZ.gif + 25 $tmpdir/lowZ.gif + 5 $FSLDIR/etc/luts/ramp.gif + 5 $tmpdir/high.gif $tmpdir/zinfo.gif
else
pngappend $tmpdir/lowZ.gif + 5 $FSLDIR/etc/luts/ramp.gif + 5 $tmpdir/high.gif $tmpdir/zinfo.gif
fi
convert $tmpdir/zinfo.gif $tmpdir/zinfo.png
fi
#----------------------------------------------------------------------#
if [ $set_cnt -gt 1 ]
then
if [ $SglVXL -eq 1 ]
then
xstr=`printf "X:~%6d~[%6.2f~mm]" $xslc $mmX`
ystr=`printf "Y:~%6d~[%6.2f~mm]" $yslc $mmY`
zstr=`printf "Z:~%6d~[%6.2f~mm]" $zslc $mmZ`
eqn2gif -text "$xstr" $tmpdir/Xvxlpos.gif 1.5 > /dev/null 2>&1
eqn2gif -text "$ystr" $tmpdir/Yvxlpos.gif 1.5 > /dev/null 2>&1
eqn2gif -text "$zstr" $tmpdir/Zvxlpos.gif 1.5 > /dev/null 2>&1
pngappend $tmpdir/Xvxlpos.gif - 5 $tmpdir/Yvxlpos.gif - 5 $tmpdir/Zvxlpos.gif $tmpdir/slcinfo.gif
if [ "$statmap" ]
then
pngappend $tmpdir/slcinfo.gif - 50 $tmpdir/zinfo.png $tmpdir/slcinfo.gif
fi
pngappend $tmpdir/selY.png + 0 $tmpdir/selX.png $tmpdir/SLCsel.png
pngappend $tmpdir/selZ.png + 25 $tmpdir/slcinfo.gif $tmpdir/tmpSLCsel.png
pngappend $tmpdir/SLCsel.png - 0 $tmpdir/tmpSLCsel.png $tmpdir/SLCsel.png
pngappend $tmpdir/Yset.png + 0 $tmpdir/Xset.png $tmpdir/tmp_out1.png
pngappend $tmpdir/Zset.png + 0 $tmpdir/SLCsel.png $tmpdir/tmp_out2.png
pngappend $tmpdir/tmp_out1.png - 0 $tmpdir/tmp_out2.png $outnm
else
cnt=0
for cstr in $png_str
do
cnt=$(($cnt+1))
if [ $cnt -eq 1 ]
then
appstr="pngappend $cstr"
else
appstr="$appstr - $pxl $cstr"
fi
done
appstr="$appstr $outnm"
eval $appstr
fi
else
cp $png_str $outnm
fi
if [ $SglVXL -eq 0 ]
then
if [ "$statmap" ]
then
pngappend $outnm - $tmpdir/zinfo.png $outnm
fi
fi
#----------------------------------------------------------------------#
if [ $do_keep -eq 0 ]
then
rm -r $tmpdir
fi
#!/bin/bash
#
Usage() {
cat << EOF
Usage: slice_selection <flnm> [options]
OPTIONS:
-ol overlay image (must have the same dimensions as <flnm>!)
-out filename of the image file (png)
-s scaling factor
-u do not show right side marker
-x -y -z specify set of slices to save as image (e.g. -z "2 4 6 8 10")
numbers > 0 specify slicenumbers, numbers < 0 specify proportions.
-comb create a huge image with slices for all dimensions combined
otherwise for each dimension a seperate image will be created.
-keep do not delete temporary files
###########################################################
## (c) wolf zinke (2008) - part of the MaFIA toolbox ##
## > MAcaque Functional Image Analysis < ##
## for comments and questions: [log in to unmask] ##
###########################################################
EOF
exit 1
}
#----------------------------------------------------------------------#
if [ $# -lt 1 ]; then
Usage
else
flnm=`remove_ext $1`;
shift
fi
imgfl=${flnm}_slices.png
sc=1
olimg=""
do_ol=0
do_x=0
do_y=0
do_z=0
slc_spec=0
do_comb=0
do_keep=0
uopt=""
while [ $# -gt 0 ] ;
do
case $1 in
-ol) olimg=$2
do_ol=1
shift 2
;;
-out) imgfl=$2
shift 2
;;
-x) X=$2
do_x=1
slc_spec=1
shift 2
;;
-y) Y=$2
do_y=1
slc_spec=1
shift 2
;;
-z) Z=$2
do_z=1
slc_spec=1
shift 2
;;
-s) sc=$2
shift 2
;;
-0) uopt=-u
shift
;;
-comb) do_comb=1
shift
;;
-keep) do_keep=1
shift
;;
-*) echo "Wrong option: <$1>"
echo ""
Usage
;;
*) break
;;
esac
done
if [ $slc_spec -eq 0 ]
then
echo ""
echo "ERROR: No slices specified!"
echo ""
exit
fi
#----------------------------------------------------------------------#
tmpdir=`tmpnam tmpSLC`
rm -f $tmpdir
mkdir $tmpdir
#----------------------------------------------------------------------#
if [ $do_ol -eq 1 ]
then
slc_call="slicer $flnm $olimg $uopt -s $sc"
else
slc_call="slicer $flnm $uopt -s $sc"
fi
if [ $do_comb -eq 1 ]
then
comb_call="pngappend"
comb_app=0
fi
#----------------------------------------------------------------------#
if [ $do_x -eq 1 ]
then
comb_x="pngappend"
xdim=`fslval $flnm dim1`
cnt=0
for cslc in $X
do
cnt=$(($cnt+1))
done
lnbrk=`Rcalc "ceiling(sqrt($cnt))"`
cnt=0
col_cnt=0
for cslc in $X
do
if [ $cslc -gt $xdim ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in X dimension"
echo ""
rm -r $tmpdir
exit
fi
slc_call="$slc_call -x $cslc $tmpdir/slx_${cslc}.png"
cnt=$(($cnt+1))
col_cnt=$(($col_cnt+1))
if [ $cnt -eq 1 ]
then
comb_x="$comb_x $tmpdir/slx_${cslc}.png"
else
if [ $do_comb -eq 1 ]
then
comb_x="$comb_x + 10 $tmpdir/slx_${cslc}.png"
else
if [ $col_cnt -gt $lnbrk ]
then
comb_x="$comb_x - 10 $tmpdir/slx_${cslc}.png"
col_cnt=1
else
comb_x="$comb_x + 10 $tmpdir/slx_${cslc}.png"
fi
fi
fi
done
comb_x="$comb_x $tmpdir/slx.png"
if [ $do_comb -eq 1 ]
then
if [ $comb_app -eq 0 ]
then
comb_call="$comb_call $tmpdir/slx.png"
else
comb_call="$comb_call - 10 $tmpdir/slx.png"
fi
comb_app=1
fi
fi
#----------------------------------------------------------------------#
if [ $do_y -eq 1 ]
then
comb_y="pngappend"
ydim=`fslval $flnm dim2`
cnt=0
for cslc in $Y
do
cnt=$(($cnt+1))
done
lnbrk=`Rcalc "ceiling(sqrt($cnt))"`
cnt=0
col_cnt=0
for cslc in $Y
do
if [ $cslc -gt $ydim ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in Y dimension"
echo ""
rm -r $tmpdir
exit
fi
slc_call="$slc_call -y $cslc $tmpdir/sly_${cslc}.png"
cnt=$(($cnt+1))
col_cnt=$(($col_cnt+1))
if [ $cnt -eq 1 ]
then
comb_y="$comb_y $tmpdir/sly_${cslc}.png"
else
if [ $do_comb -eq 1 ]
then
comb_y="$comb_y + 10 $tmpdir/sly_${cslc}.png"
else
if [ $col_cnt -gt $lnbrk ]
then
comb_y="$comb_y - 10 $tmpdir/sly_${cslc}.png"
col_cnt=1
else
comb_y="$comb_y + 10 $tmpdir/sly_${cslc}.png"
fi
fi
fi
done
comb_y="$comb_y $tmpdir/sly.png"
if [ $do_comb -eq 1 ]
then
if [ $comb_app -eq 0 ]
then
comb_call="$comb_call $tmpdir/sly.png"
else
comb_call="$comb_call - 10 $tmpdir/sly.png"
fi
comb_app=1
fi
fi
#----------------------------------------------------------------------#
if [ $do_z -eq 1 ]
then
comb_z="pngappend"
zdim=`fslval $flnm dim3`
cnt=0
for cslc in $Z
do
cnt=$(($cnt+1))
done
lnbrk=`Rcalc "ceiling(sqrt($cnt))"`
cnt=0
col_cnt=0
for cslc in $Z
do
if [ $cslc -gt $zdim ]
then
echo ""
echo "ERROR: Selected slice <$cslc> exceed number of slices in Z dimension"
echo ""
rm -r $tmpdir
exit
fi
slc_call="$slc_call -z $cslc $tmpdir/slz_${cslc}.png"
cnt=$(($cnt+1))
col_cnt=$(($col_cnt+1))
if [ $cnt -eq 1 ]
then
comb_z="$comb_z $tmpdir/slz_${cslc}.png"
else
if [ $do_comb -eq 1 ]
then
comb_z="$comb_z + 10 $tmpdir/slz_${cslc}.png"
else
if [ $col_cnt -gt $lnbrk ]
then
comb_z="$comb_z - 10 $tmpdir/slz_${cslc}.png"
col_cnt=1
else
comb_z="$comb_z + 10 $tmpdir/slz_${cslc}.png"
fi
fi
fi
done
comb_z="$comb_z $tmpdir/slz.png"
if [ $do_comb -eq 1 ]
then
if [ $comb_app -eq 0 ]
then
comb_call="$comb_call $tmpdir/slz.png"
else
comb_call="$comb_call - 10 $tmpdir/slz.png"
fi
comb_app=1
fi
fi
#----------------------------------------------------------------------#
eval $slc_call
#----------------------------------------------------------------------#
if [ $do_x -eq 1 ]
then
eval $comb_x
fi
#----------------------------------------------------------------------#
if [ $do_y -eq 1 ]
then
eval $comb_y
fi
#----------------------------------------------------------------------#
if [ $do_z -eq 1 ]
then
eval $comb_z
fi
#----------------------------------------------------------------------#
if [ $do_comb -eq 1 ]
then
comb_call="$comb_call ${imgfl}.png"
eval $comb_call
else
if [ $do_x -eq 1 ]
then
cp $tmpdir/slx.png ${imgfl}_x.png
fi
if [ $do_z -eq 1 ]
then
cp $tmpdir/sly.png ${imgfl}_y.png
fi
if [ $do_z -eq 1 ]
then
cp $tmpdir/slz.png ${imgfl}_z.png
fi
fi
#----------------------------------------------------------------------#
if [ $do_keep -eq 0 ]
then
rm -r $tmpdir
fi
#!/bin/bash
#
Usage() {
cat << EOF
Usage: Rcalc <"expression">
evaluates the expression by piping it to R (R syntax applies)
###########################################################
## (c) wolf zinke (2008) - part of the MaFIA toolbox ##
## for comments and questions: [log in to unmask] ##
###########################################################
EOF
exit 1
}
if [ $# -lt 1 ]; then
Usage
else
funcal=$1
fi
tmpfl=`tmpnam tmpR`
funcal="x = $funcal; write.table(x, file = '$tmpfl',row.names=F,col.names=F); q();"
#funcal="x = $funcal; write(x, file = $tmpfl,append=FALSE); q();"
echo "$funcal" | R --vanilla --slave
cat $tmpfl
rm $tmpfl
|