Last active
January 2, 2016 03:49
-
-
Save jefferis/8246019 to your computer and use it in GitHub Desktop.
Trying to use CMTK fit_spline_xform to fit the inverse of an existing transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Setup | |
mkdir images | |
mkdir refbrain | |
curl -o images/A.nrrd http://flybrain.mrc-lmb.cam.ac.uk/cmtk/A.nrrd | |
curl -o refbrain/B.nrrd http://flybrain.mrc-lmb.cam.ac.uk/cmtk/B.nrrd | |
AREG="B_A_9dof.list" | |
REG="B_A_warp.list" | |
# Generate registration 1 for A onto B | |
# munger -b /opt/local/bin/ -aw -l f -C 20 -R 1 -A '--accuracy 2' -W '--accuracy 2' -s 'refbrain/B.nrrd' 'images' | |
registration -i -v --dofs 6 --dofs 9 --accuracy 2 -o "$AREG" refbrain/B.nrrd images/A.nrrd | |
warp -v --fast -e 16 --grid-spacing 40 --energy-weight 1e-1 --refine 1 --coarsest 20 --accuracy 2 -o "$REG" "$AREG" | |
# Reformat A onto B using registration 1 | |
reformatx --outfile A_onto_B.nrrd --floating 'images/A.nrrd' 'refbrain/B.nrrd' "$REG" | |
# Invert our previous step, giving an A' similar to A | |
reformatx --outfile A_prime.nrrd --floating 'A_onto_B.nrrd' 'images/A.nrrd' --inverse "$REG" | |
# Fit B-spline to transformation of A onto B using image B to define output domain | |
fit_spline_xform --fit-affine-first --final-cp-dims '10,6,4' --levels 3 --output A_onto_B_spline 'refbrain/B.nrrd' "$REG" | |
# Now produce an image A_onto_B_spline.nrrd, using the spline fit | |
reformatx --outfile A_onto_B_spline.nrrd --floating 'images/A.nrrd' 'refbrain/B.nrrd' A_onto_B_spline | |
# not identical to A_onto_B.nrrd, but certainly similar | |
# OK ALL FINE SO FAR BUT ... | |
# now we want to fit_spline_xform to the INVERSE of our original image-based transform | |
# Fit B-spline to inverse transformation (ie we want A to be the reference image) | |
fit_spline_xform --fit-affine-first --final-cp-dims '10,6,4' --levels 3 --output inverse_spline 'images/A.nrrd' -- --inverse "$REG" | |
# Hmm, what's odd here is that the initial affine is (almost) the identity transform | |
# and the spline component is a completely regular grid | |
# Well let's go ahead and produce an image A'_spline, using the B-spline fit | |
reformatx --outfile A_prime_spline.nrrd --floating 'A_onto_B.nrrd' 'images/A.nrrd' inverse_spline | |
# yes, no joy there | |
# just in case, check without fitting initial affine | |
fit_spline_xform --final-cp-dims '10,6,4' --levels 3 --output inverse_spline_noaff 'images/A.nrrd' -- --inverse "$REG" | |
reformatx --outfile A_prime_spline_noaff.nrrd --floating 'A_onto_B.nrrd' 'images/A.nrrd' inverse_spline_noaff | |
# same deal - completely regular spline grid | |
# just in case, check with a full size B spline field | |
fit_spline_xform --fit-affine-first --final-cp-dims '33,17,9' --levels 3 --output inverse_spline_full 'images/A.nrrd' -- --inverse "$REG" | |
# Produce an image A'_spline, using the B-spline fit | |
reformatx --outfile A_prime_spline_full.nrrd --floating 'A_onto_B.nrrd' 'images/A.nrrd' inverse_spline_full | |
# maybe we should still be giving B as the reference image (since it _is_ the reference for the registration we are inverting) | |
fit_spline_xform --fit-affine-first --final-cp-dims '10,6,4' --levels 3 --output inverse_spline_B 'refbrain/B.nrrd' -- --inverse "$REG" | |
# do the reformating | |
reformatx --outfile A_prime_spline_BA.nrrd --floating 'A_onto_B.nrrd' 'images/A.nrrd' inverse_spline_B | |
# nope that didn't do the trick! | |
# SO HOW DO WE USE FIT_SPLINE_XFORM ON THE _INVERSE_ OF AN EXISTING REGISTRATION? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment