#!/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 1 fi A=$1 B=$2 shift 2 lesion_thr=0.5 nclasses=2 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 echo "working" > ${A}_lesions.txt #### T1 ################################################################################ # brain-extract t1 and run segmentation; pve_0 should be CSF only ${FSLDIR}/bin/bet $A ${A}_brain -m ${FSLDIR}/bin/fast1 -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/fslmaths ${FSLDIR}/etc/standard/avg152T1_strucseg -thr 3.5 -bin -dilM -dilM -dilM 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/fslmaths 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/fslmaths ${A}_brain_pve_0 -thr 0.3 -bin ${A}_csf ${FSLDIR}/bin/fslmaths ${A}_csf -kernel 2D -dilM -dilM -dilM -dilM -dilM -sub strucseg_2_${A}_brain -thr 0.5 -bin ${A}_grot ${FSLDIR}/bin/fslmaths ${A}_csf -kernel 2D -dilM -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/fslmaths $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/fast1 $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/fslmaths ${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/fslmaths ${A}_csf_dil -mul -1 -add 1 -mul ${A}_lesion+CSF ${A}_lesions -odt float ${FSLDIR}/bin/fslmaths ${A}_lesions -thr $lesion_thr ${A}_lesions_thr -odt float echo `${FSLDIR}/bin/fslstats ${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.png ${FSLDIR}/bin/slicer ${A}_brain_seg strucseg_2_${A}_brain -A 400 ${A}_brain_seg.png ${FSLDIR}/bin/flirt -in $B -ref $A -out ${B}_grot -applyxfm -init ${B}_to_${A}.mat ; ${FSLDIR}/bin/slicer ${B}_grot -A 400 $B.png ${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.png ${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.png ${FSLDIR}/bin/pngappend ${A}.png ${A}_brain_seg.png ${B}.png ${B}_brain_seg.png ${A}_lesions_render.png ${A}_lesions.png #### clean up ######################################################################### /bin/rm -f ${A}.png ${B}.png ${A} ${B} ${A}_brain_seg.png ${B}_brain_seg.png ${A}_lesions_render* ${A}_brain_delesioned_seg.png ${A}_grot* ${B}_grot*