AFNI version info (afni -ver):
Apr 4 2024 (Version AFNI_24.1.00 'Publius Septimius Geta')

hi mathematically-more-inclined:

if i wanted to calculate a mid-point affine transform between 2 images of the same brain (different runs, so they've moved a little), would i just divide a resulting matrix by 2 using 1dmatcalc? so this would be like the tx from A -> B
find the midpoint (analogous to 'blip'-style mid-points only affine-only)
move A to that midpoint
also take that transform-divided-by-2 and use it as an inverse to move B -> A

in other words both images would end up in the middle space aligned, and with equal resamplings. possible, right? am i on the right track?

You might want the "square root of the matrix" for the intermediate transform, which is what the -S opt does in cat_matvec; from the help:

-S = square root of the matrix
Note: Not all matrices have square roots!
The square root of a matrix will do 'half' the transformation.
One application: 3dLRflip + 3dAllineate to register a volume
to its mirror image, then apply half the transformation to
bring it into vertical alignment.

amazing! that totally worked, thank you Paul. here's my code for anyone listening in:

#have 2 images (in my case mean functional epis) equally resampled as they meet in the middle. for methods testing:
3dAllineate -source B.nii.gz -base A.nii.gz -1Dparam_save BtoA_paramsave -1Dmatrix_save BtoA_mtxsave -prefix viewStep1.nii.gz -nomask -cmass -cost lpa+ -warp shift_rotate -final wsinc5
#calculate intermediate of the transform:
cat_matvec -ONELINE BtoA_mtxsave.aff12.1D -S > intermed.aff12.1D
#apply intermediate to the B image
3dAllineate -source B.nii.gz -prefix meanf_B_intermed.nii.gz -1Dmatrix_apply intermed.aff12.1D -final wsinc5
#make inverse of intermediate:
cat_matvec -ONELINE intermed.aff12.1D -I > inv_of_intermed.aff12.1D
#apply inverse intermediate to A image, so they meet in the middle
3dAllineate -source A.nii.gz -prefix meanf_A_intermed.nii.gz -1Dmatrix_apply inv_of_intermed.aff12.1D -final wsinc5

1 Like

The
National Institute of Mental Health (NIMH) is part of the National Institutes of
Health (NIH), a component of the U.S. Department of Health and Human
Services.