-
Stephen Smith authoredStephen Smith authored
lesions_0.1 4.21 KiB
#!/bin/sh
# lesions.....this doesn't work!!
#
# Stephen Smith, FMRIB Image Analysis Group
#
# Copyright (C) 1999-2004 University of Oxford
#
# SHCOPYRIGHT
#### process options ###################################################################
if [ _$2 = _ ] ; then
echo "Usage: lesions <t1_root> <t2_root> [-f]"
echo "-f : second image is FLAIR not t2"
exit
fi
nclasses=3
t2segopts="-t2 -a"
t2lesions=$2_brain_pve_0
if [ _$3 = _-f ] ; then
echo "processing second input as FLAIR image"
nclasses=4
t2segopts=""
t2lesions=$2_brain_pve_3
fi
#### T1 ################################################################################
# brain-extract t1 and run segmentation; pve_0 should be CSF only
${FSLDIR}/bin/bet $1 $1_brain -m
${FSLDIR}/bin/fast -e -ov $1_brain
# register t1 to standard space and invert transform
${FSLDIR}/bin/flirt -ref ${FSLDIR}/etc/standard/avg152T1_brain -in $1_brain -omat $1_brain_2_std.mat
${FSLDIR}/bin/convert_xfm -inverse -omat std_2_$1_brain.mat $1_brain_2_std.mat
# dilate (6mm) standard space structural segmentation, bring into t1 space and re-binarise
${FSLDIR}/bin/avwmaths ${FSLDIR}/etc/standard/avg152T1_strucseg -thr 3.5 -bin -dil -dil -dil strucseg_2_$1_brain
${FSLDIR}/bin/flirt -in strucseg_2_$1_brain -ref $1_brain -out strucseg_2_$1_brain -applyxfm -init std_2_$1_brain.mat
${FSLDIR}/bin/avwmaths strucseg_2_$1_brain -bin strucseg_2_$1_brain
# produce t1-derived CSF mask and also dilate in-plane: 5 voxels outside central mask, 1 voxel inside mask
${FSLDIR}/bin/avwmaths $1_brain_pve_0 -thr 0.3 -bin $1_csf
${FSLDIR}/bin/avwmaths $1_csf -dil2 -dil2 -dil2 -dil2 -dil2 -sub strucseg_2_$1_brain -thr 0.5 -bin $1_grot
${FSLDIR}/bin/avwmaths $1_csf -dil2 -mul strucseg_2_$1_brain -add $1_grot -bin $1_csf_dil
#### T2 ################################################################################
# register t2 to t1 and invert transform
${FSLDIR}/bin/flirt -in $2 -ref $1 -omat $2_to_$1.mat
${FSLDIR}/bin/convert_xfm -inverse -omat $1_to_$2.mat $2_to_$1.mat
# transform t1 brain mask into t2 space, dilate slightly and apply to t2 to get t2 brain
${FSLDIR}/bin/flirt -in $1_brain_mask -out $2_brain_mask -ref $2 -applyxfm -init $1_to_$2.mat
#${FSLDIR}/bin/avwmaths $2_brain_mask -dil $2_brain_mask
${FSLDIR}/bin/avwmaths $2_brain_mask $2_brain_mask
${FSLDIR}/bin/avwmaths $2 -mas $2_brain_mask $2_brain
# run segmentation on t2; pve_0 should be CSF+lesions; transform into t1 space, remask with t1 brain mask
${FSLDIR}/bin/fast $t2segopts -c $nclasses -e -ov $2_brain
${FSLDIR}/bin/flirt -in $t2lesions -ref $1 -out $1_lesion+CSF -applyxfm -init $2_to_$1.mat
${FSLDIR}/bin/avwmaths $1_lesion+CSF -mas $1_brain_mask $1_lesion+CSF
#### combine to remove CSF from CSF+lesions ############################################
# combine masks and use to mask out CSF from t2-derived lesion+CSF probability; output lesion volume
${FSLDIR}/bin/avwmaths_32R $1_csf -mul -1 -add 1 -mul $1_lesion+CSF -thr 0.3 -bin $1_lesions+ucsf
${FSLDIR}/bin/avwmaths_32R $1_csf_dil -mul -1 -add 1 -mul $1_lesion+CSF $1_lesions
echo `${FSLDIR}/bin/avwstats $1_lesions -m -v | awk '{print "2 k " $1 " " $3 " * 1000 / p" }' | dc -` > $1_lesions.txt
echo "$1 `cat $1_lesions.txt`"
# create display output
${FSLDIR}/bin/flirt -in $2 -ref $1 -out $2_grot -applyxfm -init $2_to_$1.mat
${FSLDIR}/bin/slicer $2_grot -A 400 $2
${FSLDIR}/bin/flirt -in $2_brain_seg -ref $1 -out $2_grot2 -applyxfm -init $2_to_$1.mat
${FSLDIR}/bin/slicer $2_grot2 -i 0 $nclasses -A 400 $2_brain_seg
${FSLDIR}/bin/overlay 0 1 $1 -a $1_lesions 0.5 1 $1_lesions_render
${FSLDIR}/bin/slicer $1_lesions_render -A 400 $1_lesions_render
${FSLDIR}/bin/slicer $1_brain_seg strucseg_2_$1_brain -A 400 $1_brain_seg
${FSLDIR}/bin/slicer $1 -A 400 $1
${FSLDIR}/bin/slicer $1_lesions+ucsf -i 0 1 -A 400 $1_lesions+ucsf
${FSLCONVERT} -colors 200 +append $2 $2_brain_seg $1_lesions_render $1_brain_seg $1 $1_lesions+ucsf $1_lesions.gif
#### clean up #########################################################################
/bin/rm -f $1 $2 $1_brain_seg $2_brain_seg $1_lesions_render* $1_brain_delesioned_seg $1_lesions_render* $1_lesions+ucsf $1_grot* $2_grot*