Hi,
As Christian suggested you can nicely script the tools provided by FSL
to fullfill quiet a lot of needs. But sometimes it might be nice to have
such scripts, or at least some examples that can be used as a rough
idea. I attached some scripts that I created to produce some images with
selected slices. It makes sense only if you want to use not more than 2
stats images (sorry, but otherwise MRICron
(www.sph.sc.edu/comd/rorden/mricron) might be useful). I am a bit lazy
and use a tool that pipes math expressions into R (www.r-project.org/),
so this has to be installed or the Rcalc command be replaced with
something comparable (like ccalc from the AFNI package). I have not
tested the scripts thoroughfully, so I can't guarantee the functionality
and I would also be happy to hear about problems or bugs.
You can than easily import the images into any image processing software
(e.g. Corel Draw) and arrange them the way you like.
I hope this helps,
wolf
Christian F. Beckmann wrote:
> Hi
>
> In cases where you only need a simple stats overlay (1 or 2 stats
> images ontop of a background image) then the FSL tools 'overlay',
> 'slicer' and 'pngappend' can be used (and scripted, hurray!) without
> the need to grab anything from the screen. 'slicer' can also achieve
> the latter, i.e. produce a light-box view from all or a sub-set of all
> the slices. These are the tools used to produce the figures you see in
> the FEAT web reports.
> hth
> Christian
>
>
>
> On 24 Feb 2009, at 14:24, Michael Rohan wrote:
>
>> Hi,
>> Is it possible to have fslview place the three orthographic views in one
>> horizontal row on the screen? This will make it easier to fit grabs
>> into a
>> document (without that blank 4th place).
>>
>> Along the same lines, in the lightbox view is it possible to display a
>> subset of the slices, whether with a specified interval or a slice list?
>>
>> Thanks,
>> Mike Rohan
>
> _______________________________________________
> Christian F. Beckmann, DPhil
> Senior Lecturer, Clinical Neuroscience Department
> Division of Neuroscience and Mental Health
> Imperial College London, Hammersmith Campus
> Rm 419, Burlington Danes Bldg, Du Cane Road, London W12 0NN, UK
> Tel.: +44 (0)20 7594 6685 --- Fax: +44 (0)20 7594 6548
> Email: [log in to unmask]
> http://www.imperial.ac.uk/medicine/people/c.beckmann/
>
> Senior Research Fellow, FMRIB Centre
> University of Oxford
> JR Hospital - Oxford OX3 9DU
> Tel.: +44 (0)1865 222551 --- Fax: +44 (0)1865 222717
> Email: [log in to unmask]
> http://www.fmrib.ox.ac.uk/~beckmann
#!/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
funcal="x = $funcal; write.table(x, file = '/tmp/Rout.tmp',row.names=F,col.names=F); q();"
echo "$funcal" | R --vanilla --slave
cat /tmp/Rout.tmp
rm /tmp/Rout.tmp
#!/bin/bash
#
Usage() {
cat << EOF
Usage: vol_slicer <bg_img> <slc_num>
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
-s <sclfctr> scalinf factor
-bgint <min max> intensity range for the background image
-statrng <min max> scaling theshold
-out <outname> filenmae 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 2 ]; 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=""
rm $tmpdir
#----------------------------------------------------------------------#
# get options
while [ $# -gt 0 ] ;
do
case $1 in
-out) outnm=$2
shift 2
;;
-stat) statmap="$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
;;
-bgint) bgint="$2 $3"
shift 3
;;
-statrng) smint="$2 $3"
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;
#----------------------------------------------------------------------#
# prepare overlay image
if [ "$statmap" ]
then
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 "ERROR: negative map could only be used with one statistical map as input"
echo ""
exit
fi
fslmaths $statmap -mul -1 $tmpdir/negmap
statstr="$statstr $tmpdir/negmap $smint"
fi
#echo " overlay $trans 1 $bg_img $bgint $statstr $tmpdir/curr_img"
#exit
overlay $trans 1 $bg_img $bgint $statstr $tmpdir/curr_img
else
imcp $bg_img $tmpdir/curr_img
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 [ "$xstr" ]
then
xslices=""
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/xslcsel -odt char
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"
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc+1))
fi
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
done
overlay 0 1 $bg_img $bgint $tmpdir/xslcsel 1 4 $tmpdir/Xslc_vol
slicer $tmpdir/Xslc_vol -s $scl $sdlbl -y 0.5 $tmpdir/XselY.png -z 0.6 $tmpdir/XselZ.png
pngappend $tmpdir/XselY.png + $pxl $tmpdir/XselZ.png $tmpdir/Xsel.png
appstr="pngappend $tmpdir/Xsel.png"
for cpng in $xslices
do
appstr="$appstr + $pxl $cpng"
done
appstr="$appstr $tmpdir/Xset.png"
eval $appstr
png_str="$png_str $tmpdir/Xset.png"
set_cnt=$(($set_cnt+1))
fi
if [ "$ystr" ]
then
yslices=""
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/yslcsel -odt char
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"
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc+1))
fi
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
done
overlay 0 1 $bg_img $bgint $tmpdir/yslcsel 1 4 $tmpdir/Yslc_vol
slicer $tmpdir/Yslc_vol -s $scl $sdlbl -x 0.4 $tmpdir/YselX.png -z 0.6 $tmpdir/YselZ.png
pngappend $tmpdir/YselX.png + $pxl $tmpdir/YselZ.png $tmpdir/Ysel.png
appstr="pngappend $tmpdir/Ysel.png"
for cpng in $yslices
do
appstr="$appstr + $pxl $cpng"
done
appstr="$appstr $tmpdir/Yset.png"
eval $appstr
png_str="$png_str $tmpdir/Yset.png"
set_cnt=$(($set_cnt+1))
fi
if [ "$zstr" ]
then
zslices=""
fslmaths $tmpdir/all_slices -mul 0 $tmpdir/zslcsel -odt char
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"
if [ $do_thick -eq 1 ]
then
cslc=$(($cslc+1))
fi
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
done
overlay 0 1 $bg_img $bgint $tmpdir/zslcsel 1 4 $tmpdir/Zslc_vol
slicer $tmpdir/Zslc_vol -s $scl $sdlbl -x 0.4 $tmpdir/ZselX.png -y 0.5 $tmpdir/ZselY.png
pngappend $tmpdir/ZselX.png + $pxl $tmpdir/ZselY.png $tmpdir/Zsel.png
appstr="pngappend $tmpdir/Zsel.png"
for cpng in $zslices
do
appstr="$appstr + $pxl $cpng"
done
appstr="$appstr $tmpdir/Zset.png"
eval $appstr
png_str="$png_str $tmpdir/Zset.png"
set_cnt=$(($set_cnt+1))
fi
#----------------------------------------------------------------------#
if [ $set_cnt -gt 1 ]
then
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
else
cp $png_str $outnm
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
|