Child pages
  • Atlas to Atlas Registration with ANTS (intra or inter modality)

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
#!/bin/bash

# usage
# save this file: example 'reg_scr.sh'
# mark it as executable:
#  > chmod +x reg_scr.sh
# To register a file (source.mnc) to another file (target.mnc) and save the transform (source_to_target.xfm).
# The source and target files have masks (source_mask.mnc and target_mask.mnc) to speed up registrations and make them more accurate.
#  > ./reg_scr.sh source.mnc source_mask.mnc target.mnc target_mask.mnc source_to_target.xfm
 
parse_arr=( "$@" )
 
srcfl=${parse_arr[0]}
srcmsk=${parse_arr[1]}
tgtfl=${parse_arr[32]}
tgtmsk=${parse_arr[43]}
xfmfl=${parse_arr[54]}


srcfl_aff='source_affine.mnc'
srcmsk_aff='source_affine_mask.mnc'

xfm_aff='source_to_target_affine.xfm'
xfm_warp='source_to_target_warp.xfm'

# run affine registration
antsRegistration -d 3 \
   -o "${xfm_aff%.*}" \
   -x [${srcmsk},${tgtmsk}] \
   -a 1 -z 1 \
   -t Affine[0.25] \
   -m MI[${srcfl},${tgtfl},1,32,Regular,0.25] \
   --convergence [1000,1e-6,10] --shrink-factors 1 --smoothing-sigmas 0mm \
   --minc -v 1 --use-histogram-matching 1

# affine resample source and mask
mincresample -quiet -like ${tgtfl} -transform ${xfm_aff} ${srcfl} ${srcfl_aff}
mincresample -nearest -label -quiet -like ${tgtfl} -transform ${xfm_aff} ${srcmsk} ${srcmsk_aff}

# run non-affine registration
antsRegistration -d 3 \
   -o "${xfm_warp%.*}" \
   -x [${srcmsk_aff},${tgtmsk}] \
   -a 1 -z 1 \
   -t SyN[0.1,2,0] \
   -m MI[${srcfl_aff},${tgtfl},1,32,Regular,0.25] \
   --convergence [1000x1000x1000x1000,1e-6,10] \
   --shrink-factors 8x4x2x1 \
   --smoothing-sigmas 0.2x0.1x0.05x0mm \
   --minc -v 1 --use-histogram-matching 1

# concatenate affine and non-affine transformations
xfmconcat ${xfm_aff} ${xfm_warp} ${xfmfl}

# remove temporary files
rm ${srcfl_aff} ${srcmsk_aff} 
rm ${xfm_aff} ${xfm_aff%.*}_inverse.xfm
rm ${xfm_warp} ${xfm_warp%.*}_inverse.xfm
rm ${xfm_warp%.*}_grid_0.mnc ${xfm_warp%.*}_inverse_grid_0.mnc

...