[Neuroimaging] Extracting the brain coordinates from a nifti volume
matthew.brett at gmail.com
Tue Jun 16 10:39:43 EDT 2020
On Tue, Jun 16, 2020 at 10:28 AM serafim loukas <seralouk at hotmail.com> wrote:
> Hi Neuroimaging community,
> I have a single nifti (nii) file and I just want to extract the brain coordinates (in mm) for all voxels (i.e. the whole nii volume).
> How can I do that using nilearn/nibabel?
I think this will do what you want:
[ins] In : import numpy as np
[ins] In : import nibabel as nib
[ins] In : img = nib.load('my_image.nii')
[ins] In : vox_indices = np.indices(img.shape).transpose(1, 2, 3, 0)
[ins] In : mm = nib.affines.apply_affine(img.affine, vox_indices)
More information about the Neuroimaging