[Neuroimaging] Affine transformations
Matthew Brett
matthew.brett at gmail.com
Fri Aug 31 10:06:55 EDT 2018
Hi,
On Fri, Aug 31, 2018 at 2:57 PM, Stefan Hoffmann
<stefan.hoffmann at uni-jena.de> wrote:
>
> Dear Matthew,
>
> thanks for the fast response.
>
> Given center point at voxels (2, 3, 4) so that:
>
> T = [[1, 0, 0, -2],
> [0, 1, 0, -3],
> [0, 0, 1, -4],
> [0, 0, 0, 1]]
>
> and calculating Tinv.dot(Z).dot(R).dot(T).
>
> Would an extra translation
>
> T_extra = [[1, 0, 0, -7],
> [0, 1, 0, 7],
> [0, 0, 1, -8],
> [0, 0, 0, 1]]
>
> after the rotation be implemented as
>
> Tinv.dot(Z).dot(R).dot(T).dot(T_extra)
>
> or can it all be done at once with one T:
>
> T= [[1, 0, 0, -9],
> [0, 1, 0, 4],
> [0, 0, 1, -12],
> [0, 0, 0, 1]]
Did you catch:
http://nipy.org/nibabel/coordinate_systems.html
? Probably you did.
The transformations read from right to left, so read
Tinv.dot(Z).dot(R).dot(T).dot(T_extra)
as
First apply T_extra
Then apply T
Then apply R
Then apply Tinv
So, I think you want:
T_extra.dot(Tinv).dot(Z).dot(R).dot(T)
> Also I'd like to ask how to implement the multiplication it in Python?
>
> I know there's scipy affine_transformation on the one hand, and also the
> affine_tarnsform funtion in nipy, but I'm not sure how to use them.
The usual situation is that you first apply the image affine matrix
(voxels to RAS mm) then apply any transforms, then apply the inverted
image affine (RASmm to voxels).
Have a look at:
https://bic-berkeley.github.io/psych-214-fall-2016/resampling_with_ndimage.html
Does that help to explain how to use the Scipy functions to make a
transformed version of the image?
Cheers,
Matthew
More information about the Neuroimaging
mailing list