Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
demonstration of mrregister's linear initialisation using diagnostics images
#!/usr/bin/env bash
set -x
tmp_dir=$(mktemp -d -t mrregister_init-XXXXXXXXXX)
cd $tmp_dir
echo $tmp_dir
# ____ 0. get DWI data and create two ODFs ____
for sub in sub-02 sub-03; do
wget --quiet https://github.com/MRtrix3/script_test_data/raw/master/BIDS/"${sub}"/dwi/"${sub}"_dwi.bval
wget --quiet https://github.com/MRtrix3/script_test_data/raw/master/BIDS/"${sub}"/dwi/"${sub}"_dwi.bvec
wget --quiet https://github.com/MRtrix3/script_test_data/raw/master/BIDS/"${sub}"/dwi/"${sub}"_brainmask.nii.gz
wget --quiet https://github.com/MRtrix3/script_test_data/raw/master/BIDS/"${sub}"/dwi/"${sub}"_dwi.nii.gz
wget --quiet https://github.com/MRtrix3/script_test_data/raw/master/BIDS/"${sub}"/dwi/"${sub}"_tissue-WM_response.txt
done
for sub in sub-02 sub-03; do
tail -1 "${sub}"_tissue-WM_response.txt > rf.tmp
dwi2fod csd "${sub}"_dwi.nii.gz rf.tmp -fslgrad "${sub}"_dwi.bvec "${sub}"_dwi.bval -mask "${sub}"_brainmask.nii.gz "${sub}".mif -lmax 4
done
# ____ 1. create subject and template files ____
# in this example, sub-02.mif transformed by a rigid transformation is used as subject (source) image
# sub-03.mif smoothed is used as template (target) image
echo "0.8 0.1 0 -100
-0.1 1 0 20
0 0 1.2 4" > A.txt
transformcalc A.txt rigid R.txt
transformcalc R.txt invert Rinv.txt
mrtransform sub-02.mif -linear R.txt -reorient no subject.mif -force
mrfilter sub-03.mif smooth -std 3 template.mif -force
# _____ 2. coregister template and subject using different initialisation schemes, write diagnostics images after each stage ____
# co-register subject and template ____
# no initilisation
mrregister subject.mif template.mif -type affine -affine_scale 1,1,1 -affine_lmax 0,0,0 -affine_niter 0,1,10 \
-linstage.diagnostics.prefix initialised_none -affine_init_translation none -info
# initilise with rigid transformation
mrregister subject.mif template.mif -type affine -affine_scale 1,1,1 -affine_lmax 0,0,0 -affine_niter 0,1,10 \
-linstage.diagnostics.prefix initialised_matrix -affine_init_matrix Rinv.txt -info
# initilisation via centre of mass (not robust without masks)
mrregister subject.mif template.mif -type affine -affine_scale 1,1,1 -affine_lmax 0,0,0 -affine_niter 0,1,10 \
-linstage.diagnostics.prefix initialised_mass -affine_init_translation mass -info
# initilise nonlinear registration
mrregister subject.mif template.mif -type nonlinear -diagnostic nonlinear -affine_init_matrix Rinv.txt \
-nl_lmax 0 -nl_scale 1 -nl_niter 0 \
-transformed s_at_t.mif -info
# _____ 3. display (flick through images to see different stages)
mrview initialised_none* -mode 2 &
mrview initialised_matrix* -mode 2 &
mrview initialised_mass* -mode 2 &
mrcat s_at_t.mif template.mif $(mrcalc 0 template.mif -mult -) -axis 4 - | mrconvert - -coord 3 0 -axes 0,1,2,4 - | mrview - -mode 2 &
echo "done, please delete $tmp_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment