Skip to content

Commit

Permalink
ENH: cleaner example
Browse files Browse the repository at this point in the history
  • Loading branch information
stnava committed Aug 16, 2016
1 parent c641538 commit fe797d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 65 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ A simple and "fast" brain registration example

We use a brain mask to restrict the registration focus

Similar strategies may be used for brains with missing data e.g. lesions
Similar strategies may be used for brains with missing data e.g. lesions

Both cases are illustrated in this [example script](https://github.com/stnava/BasicBrainMapping/blob/master/bbm.sh).

From within the directory, do:

```sh
bash bbm.sh data/IXI/T_template2.nii.gz data/IXI594-Guys-1089-T1.nii.gz data/neg_lesion.nii.gz
```

![T1_lesioned](https://raw.github.com/stnava/BasicBrainMapping/master/T1_lesioned.jpg?raw=true)
![Template2T1_lesioned](https://raw.github.com/stnava/BasicBrainMapping/master/Template2T1_lesioned.jpg?raw=true)
72 changes: 8 additions & 64 deletions bbm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,12 @@ dim=3 # image dimensionality
AP="" # /home/yourself/code/ANTS/bin/bin/ # path to ANTs binaries
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=4 # controls multi-threading
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS
f=$1 ; m=$2 ; mask=$3 # fixed and moving image file names
if [[ ${#f} -eq 0 ]] ; then
echo usage is
echo $0 fixed.nii.gz moving.nii.gz fixed_brain_mask.nii.gz
exit
fi
if [[ ! -s $f ]] ; then echo no fixed $f ; exit; fi
if [[ ! -s $mask ]] ; then echo no fixed mask $mask ; exit; fi
if [[ ! -s $m ]] ; then echo no moving $m ;exit; fi
reg=${AP}antsRegistration # path to antsRegistration
its=10000x1111x5
percentage=0.25
syn="20x20x0,0,5"
nm=BBM
imgs=" $f, $m "
if [[ ! -s ${nm}0GenericAffine.mat ]] ; then
$reg -d $dim -r [ $imgs ,1] \
-m mattes[ $imgs , 1 , 32, regular, 0.05 ] \
-t translation[ 0.1 ] \
-c [1000,1.e-8,20] \
-s 4vox \
-f 6 -l 1 \
-m mattes[ $imgs , 1 , 32, regular, 0.1 ] \
-t rigid[ 0.1 ] \
-c [1000x1000,1.e-8,20] \
-s 4x2vox \
-f 4x2 -l 1 \
-m mattes[ $imgs , 1 , 32, regular, 0.1 ] \
-t affine[ 0.1 ] \
-c [$its,1.e-8,20] \
-s 4x2x1vox \
-f 3x2x1 -l 1 \
-m mattes[ $imgs , 1 , 32 ] \
-t SyN[ .20, 3, 0 ] \
-c [ $syn ] \
-s 1x0.5x0vox \
-f 4x2x1 -l 1 -u 1 -z 1 -x $mask --float 1 \
-o [${nm},${nm}_diff.nii.gz,${nm}_inv.nii.gz]
${AP}antsApplyTransforms -d $dim -i $m -r $f -n linear -t ${nm}1Warp.nii.gz -t ${nm}0GenericAffine.mat -o ${nm}_warped.nii.gz --float 1
fi

echo Lesion study uses the affine mapping from the previous result.
echo One could also "revise" the template mask by the lesion mask but
echo here we assume the affine map is not corrupted by the lesion.
echo We do, however, mask the deformation estimation with a lesion mask.
origmat=${nm}0GenericAffine.mat
nm=BBM_Lesion
SmoothImage 3 data/lesion.nii.gz 2 data/neg_lesion.nii.gz
ImageMath 3 data/neg_lesion.nii.gz CorruptImage data/neg_lesion.nii.gz
ImageMath 3 data/neg_lesion.nii.gz Neg data/neg_lesion.nii.gz
MultiplyImages 3 data/neg_lesion.nii.gz $2 data/T1_lesioned.nii.gz
m=data/T1_lesioned.nii.gz
imgs=" $m, $f "
myit=1000
$reg -d $dim -r [${origmat},1] \
-m mattes[ $imgs , 1 , 32 ] \
-t SyN[ .20, 3, 0.1 ] \
-c [ 30x20x0 ] \
-s 1x0.5x0vox \
-f 4x2x1 -l 1 -u 1 -z 1 -x data/neg_lesion.nii.gz \
-o [${nm},${nm}_diff.nii.gz,${nm}_inv.nii.gz]
ExtractSliceFromImage 3 data/T1_lesioned.nii.gz temp.nii.gz 1 120
ConvertImagePixelType temp.nii.gz T1_lesioned.jpg 1
ExtractSliceFromImage 3 ${nm}_diff.nii.gz temp.nii.gz 1 120
ConvertImagePixelType temp.nii.gz Template2T1_lesioned.jpg 1
echo Users should consider doing affine registration without the mask
echo and deformable registration with the mask
MultiplyImages 3 data/IXI594-Guys-1089-T1.nii.gz data/neg_lesion.nii.gz data/T1_lesioned.nii.gz
antsRegistrationSyNQuick.sh -d 3 -f data/IXI/T_template2.nii.gz \
-m data/T1_lesioned.nii.gz -t s -o ${nm}_diff -x data/neg_lesion.nii.gz
rm grid.nii.gz jacobian.nii.gz
CreateJacobianDeterminantImage 3 ${nm}_diff1Warp.nii.gz jacobian.nii.gz 1
CreateWarpedGridImage 3 ${nm}_diff1Warp.nii.gz grid.nii.gz 1x0x1 10x10x10 3x3x3
Empty file removed data/IXI/Icon
Empty file.
Binary file modified data/IXI594-Guys-1089-T1.nii.gz
Binary file not shown.
Binary file modified data/neg_lesion.nii.gz
Binary file not shown.

0 comments on commit fe797d8

Please sign in to comment.