-
Stephen Smith authoredStephen Smith authored
lesions_0.2 4.56 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] [-lt <thr>]"
echo "-f : second image is FLAIR not T2"
echo "-lt <thr> : set lesion threshold (default 0.5)"
exit
fi
A=$1
B=$2
shift 2
lesion_thr=0.5
nclasses=3
t2segopts="-t2 -a"
t2lesions=${B}_brain_pve_0
for opts in $@ ; do
if [ $opts = -f ] ; then
echo "processing second input as FLAIR image"
nclasses=4
t2segopts=""
t2lesions=${B}_brain_pve_3
shift
fi
if [ $opts = -lt ] ; then
lesion_thr=$2
shift 2
fi
done
#### T1 ################################################################################
# brain-extract t1 and run segmentation; pve_0 should be CSF only
${FSLDIR}/bin/bet $A ${A}_brain -m
${FSLDIR}/bin/fast -e -ov ${A}_brain
# register t1 to standard space and invert transform
${FSLDIR}/bin/flirt -ref ${FSLDIR}/etc/standard/avg152T1_brain -in ${A}_brain -omat ${A}_brain_2_std.mat
${FSLDIR}/bin/convert_xfm -inverse -omat std_2_${A}_brain.mat ${A}_brain_2_std.mat
# dilate (6mm) standard space ventricles+deep-grey, bring into t1 space and re-binarise to make "CENTRAL MASK"
${FSLDIR}/bin/avwmaths ${FSLDIR}/etc/standard/avg152T1_strucseg -thr 3.5 -bin -dil -dil -dil strucseg_2_${A}_brain
${FSLDIR}/bin/flirt -in strucseg_2_${A}_brain -ref ${A}_brain -out strucseg_2_${A}_brain -applyxfm -init std_2_${A}_brain.mat
${FSLDIR}/bin/avwmaths strucseg_2_${A}_brain -bin strucseg_2_${A}_brain
# produce t1-derived CSF mask and also dilate in-plane: 5 voxels outside CENTRAL MASK, 1 voxel inside mask
${FSLDIR}/bin/avwmaths ${A}_brain_pve_0 -thr 0.3 -bin ${A}_csf
${FSLDIR}/bin/avwmaths ${A}_csf -dil2 -dil2 -dil2 -dil2 -dil2 -sub strucseg_2_${A}_brain -thr 0.5 -bin ${A}_grot
${FSLDIR}/bin/avwmaths ${A}_csf -dil2 -mul strucseg_2_${A}_brain -add ${A}_grot -bin ${A}_csf_dil
#### T2 or FLAIR #######################################################################
# register t2 to t1 and invert transform
${FSLDIR}/bin/flirt -in $B -ref $A -omat ${B}_to_${A}.mat
${FSLDIR}/bin/convert_xfm -inverse -omat ${A}_to_${B}.mat ${B}_to_${A}.mat
# transform t1 brain mask into t2 space and apply to t2 to get t2_brain
${FSLDIR}/bin/flirt -in ${A}_brain_mask -out ${B}_brain_mask -ref $B -applyxfm -init ${A}_to_${B}.mat
${FSLDIR}/bin/avwmaths $B -mas ${B}_brain_mask ${B}_brain
# run segmentation on t2; $t2lesions should be CSF+lesions; transform into t1 space, remask with t1 brain mask
${FSLDIR}/bin/fast $t2segopts -c $nclasses -e -ov ${B}_brain
${FSLDIR}/bin/flirt -in $t2lesions -ref $A -out ${A}_lesion+CSF -applyxfm -init ${B}_to_${A}.mat
${FSLDIR}/bin/avwmaths ${A}_lesion+CSF -mas ${A}_brain_mask ${A}_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 ${A}_csf_dil -mul -1 -add 1 -mul ${A}_lesion+CSF ${A}_lesions
${FSLDIR}/bin/avwmaths_32R ${A}_lesions -thr $lesion_thr ${A}_lesions_thr
echo `${FSLDIR}/bin/avwstats ${A}_lesions_thr -m -v | awk '{print "2 k " $1 " " $3 " * 1000 / p" }' | dc -` > ${A}_lesions.txt
echo "$A `cat ${A}_lesions.txt`"
# create display output
${FSLDIR}/bin/slicer $A -A 400 $A
${FSLDIR}/bin/slicer ${A}_brain_seg strucseg_2_${A}_brain -A 400 ${A}_brain_seg
${FSLDIR}/bin/flirt -in $B -ref $A -out ${B}_grot -applyxfm -init ${B}_to_${A}.mat ; ${FSLDIR}/bin/slicer ${B}_grot -A 400 $B
${FSLDIR}/bin/flirt -in ${B}_brain_seg -ref $A -out ${B}_grot -applyxfm -init ${B}_to_${A}.mat ; ${FSLDIR}/bin/slicer ${B}_grot -i 0 $nclasses -A 400 ${B}_brain_seg
${FSLDIR}/bin/overlay 0 1 $A -a ${A}_lesions $lesion_thr 1 ${A}_lesions_render ; ${FSLDIR}/bin/slicer ${A}_lesions_render -A 400 ${A}_lesions_render
${FSLCONVERT} -colors 200 +append $A ${A}_brain_seg $B ${B}_brain_seg ${A}_lesions_render ${A}_lesions.gif
#### clean up #########################################################################
/bin/rm -f $A $B ${A}_brain_seg ${B}_brain_seg ${A}_lesions_render* ${A}_brain_delesioned_seg ${A}_lesions_render* ${A}_grot* ${B}_grot*