# Registration an MRI image to another coordinate system

I have a NIFTI image that I want to register to another coordinate system (I am not sure if registration
is the correct technical term here) using a given affine transformation matrix.

The affine matrix of NIFTI image is

``````array([[ -1.,  -0.,  -0.,   0.],
[ -0.,  -1.,  -0., 239.],
[  0.,   0.,   1.,   0.],
[  0.,   0.,   0.,   1.]])

``````

And the target affine matrix is:

``````array([[ -1.,  -0.,  -0.,   0.],
[ -0.,   1.,  -0., 239.],
[  0.,   0.,   1.,   0.],
[  0.,   0.,   0.,   1.]])
``````

The difference between the two matrices is the (2,2) element.

A snippet of a slice in the z-direction for the MRI image is:

And my code to do the registration is:

``````  nifti = nilearn.image.resample_img(nifti, target_affine=target_affine, target_shape=nifti.shape,
interpolation='nearest')

``````

However, the resulting NIFTI image is all zeros. Based on my understanding, the new NIFTI image should be flipped around the second dimension but I think my understanding is off.

1. What causes the registered NIFTI image to be zero?
2. How to fix this problem?

`Nilearn` resampling fails for such transformation. I am not sure what the reason is. I had to use AFNI program `3dresample`.

Thank you for sharing. How did you use `3dresample` in your case?