dorianps / LINDA

Lesion Identification with Neighborhood Data Analysis
Apache License 2.0
20 stars 4 forks source link

Applying transformation matrices from LINDA #30

Closed yqliu9240 closed 4 years ago

yqliu9240 commented 4 years ago

Hello,

I have a question of how to transform ROIs from MNI space to the patient's T1 space, using LINDA output. I have successfully transformed a lesioned brain to MNI using LINDA. Now I want to reverse the transformation. I know when transforming from T1 to MNI, I use these four matrices: matrices = c(warpmni, affmni, affpenn, warppenn), inverting the affpenn. When doing the opposite, what would be the order of the 4 matrices, and which ones to invert?

Thanks!

dorianps commented 4 years ago

This is always complicated, see if this helps:

When registering simply A-->B, the transforms are ordered this way:

to bring A to B: warp forward -> affine forward
to bring B to A: affine inverse -> warp inverse

this is a scheme of what registrations are performed in LINDA

(the arrows indicate what is moving towards what is fixed)

Subject <-- Penn --> Ch2 MNI

LET'S SET THE TRANSFORM FILES

# these transforms come from a registration of 
# Penn template (moving) to Ch2 MNI template (fixed)
penn2mni.warp.fwd = "templateToCh2_1Warp.nii.gz"
penn2mni.warp.inv = "templateToCh2_1InverseWarp.nii.gz"
penn2mni.affine = "templateToCh2_0GenericAffine.mat"
# these transforms come from LINDA registering the
# Penn template (moving) to the subject T1w (fixed)
penn2native.warp.fwd = "*_1Warp.nii.gz"
penn2native.warp.inv = "*_1InverseWarp.nii.gz"
penn2native.affine = "*_0GenericAffine.mat"

Native to Ch2 concatenated transforms (this is what you currently do)

# when concatenating registrations the last one goes first
# In this case Penn-->MNI is first (forward) and Penn-->Subject second (inverse)
matrices = c(penn2mni.warp.fwd, 
             penn2mni.affine, 
             penn2native.affine,
             penn2native.warp.inv
             )
whichtoinvert = c(0,
                  0,
                  1,
                  0
                  )

Ch2 to native concatenated transforms (what you asked)

# In this case Penn-->Subject is first (forward) and Penn-->MNI second (inverse)
matrices = c(penn2native.warp.fwd,
             penn2native.affine,
             penn2mni.affine,
             penn2mni.warp.inv
             )

whichtoinvert = c(0,
                  0,
                  1,
                  0
                  )

You may want to double-check all works as expected, I don't use these frequently myself.

yqliu9240 commented 4 years ago

This worked, thank you so much!