#!/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 1 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/fast1 -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/fast1 $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}.png ${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.png ${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.png ${FSLDIR}/bin/slicer ${1}_brain_seg strucseg_2_${1}_brain -A 400 ${1}_brain_seg.png ${FSLDIR}/bin/slicer ${1} -A 400 ${1}.png ${FSLDIR}/bin/slicer ${1}_lesions+ucsf -i 0 1 -A 400 ${1}_lesions+ucsf.png ${FSLDIR}/bin/pngappend ${2} ${2}_brain_seg ${1}_lesions_render ${1}_brain_seg ${1} ${1}_lesions+ucsf ${1}_lesions.gif #### clean up ######################################################################### /bin/rm -f ${1}.png ${2}.png ${2} ${1} ${1}_brain_seg.png ${2}_brain_seg.png ${1}_lesions_render* ${1}_brain_delesioned_seg.png ${1}_lesions_render* ${1}_lesions+ucsf.png ${1}_grot* ${2}_grot*