[Neuroimaging] affine issue (?)
Christophe Pallier
christophe at pallier.org
Thu Jul 13 10:00:48 EDT 2017
Thanks JB & Matthew !!! I should have thought about it...
Chris
--
Christophe Pallier
Personal web site: http://www.pallier.org
Lab web site: http://www.unicog.org
Email: christophe at pallier.org
Tel: +33 (0) 1 69 08 79 34
Address:
INSERM-CEA Cognitive Neuroimaging Lab, Neurospin, bat 145,
91191 Gif-sur-Yvette Cedex, FRANCE
On Thu, Jul 13, 2017 at 3:59 PM, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
>
> On Thu, Jul 13, 2017 at 2:40 PM, Christophe Pallier
> <christophe at pallier.org> wrote:
>> Hello,
>>
>> I have an nii image (a contrast computed by SPM, in the MNI space),
>> which, according to SPM, has the following affine:
>>
>>
>>>> V.mat
>> 2 0 0 -74
>> 0 2 0 -108
>> 0 0 2 -66
>> 0 0 0 1
>>
>>
>> However, the same image loaded with nibabel yields a different affine:
>> [[ 2. 0. 0. -72.00000763]
>> [ 0. 2. 0. -106. ]
>> [ 0. 0. 2. -64. ]
>> [ 0. 0. 0. 1. ]]
>
> Right - what JB said - the affine is the mapping from voxel coordinate
> to mm coordinate. For Matlab, the voxel coordinates are 1-based, so
> the first voxel is coordinate (1, 1, 1) whereas for Python (or C) the
> first coordinate is (0, 0, 0).
>
> For example, you can think of the Matlab affine as the composition of
> the translation taking the first coordinate to 0, 0, 0, followed by
> the Python affine:
>
> import numpy as np
> py_affine = np.array([[ 2., 0., 0., -72.00000763],
> [ 0., 2., 0., -106. ],
> [ 0., 0., 2., -64. ],
> [ 0., 0., 0., 1. ]])
>
> from_111 = np.array([[1, 0, 0, -1],
> [0, 1, 0, -1],
> [0, 0, 1, -1],
> [0, 0, 0, 1]])
>
> print(py_affine.dot(from_111))
>
> This gives:
>
> [[ 2. 0. 0. -74.00000763]
> [ 0. 2. 0. -108. ]
> [ 0. 0. 2. -66. ]
> [ 0. 0. 0. 1. ]]
>
> Cheers,
>
> Matthew
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
More information about the Neuroimaging
mailing list