JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for FSL Archives


FSL Archives

FSL Archives


FSL@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Monospaced Font

LISTSERV Archives

LISTSERV Archives

FSL Home

FSL Home

FSL  July 2011

FSL July 2011

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: scripting question: display one slice per subject

From:

wolf zinke <[log in to unmask]>

Reply-To:

FSL - FMRIB's Software Library <[log in to unmask]>

Date:

Wed, 13 Jul 2011 13:14:39 +0200

Content-Type:

multipart/mixed

Parts/Attachments:

Parts/Attachments

text/plain (38 lines) , vol_slicer (588 lines) , slice_selection (358 lines) , Rcalc (38 lines)

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



Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

May 2024
April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager