Mni coords to array indices missing in nilearn?

Hi,

I needed the inverse function to nilearn.image.coord_transform
I didn’t find in nilearn, so I had to implement it.
I believe it should be there, already.
(maybe I should have opened this as an enhancement request in github)

What I’ve done is simply inverting the affine and multiply it by the needed coordinate, and then I get the indices…
Any comments about this pseudo code or a suggested pseudo code for implementing this inverse function?

@ChrisGorgolewski
@GaelVaroquaux

(Edit: I’ve tested my implementation and it seems fine (extracted some known region and compared its mean with masker.fit_transform and asserted that coord_transform(myfunction((x,y,z))=(x,y,z) ))

Thanks!

Hi @brai,

Inverse transforms of affines sounds like something nibabel would have solved,
you can check out their affine example (but the entire page is a great read to understand coordinates/coordinate systems)

Best,
James

1 Like

Hi, indeed going from coordinates to voxel indices is just mulitplying by the inverse affine and taking the integer part of the result. you can pass the inverse affine to coord_transform or just use np.dot, not sure a new function is needed for that

1 Like