[Neuroimaging] Extracting the brain coordinates from a nifti volume
seralouk at hotmail.com
Tue Jun 16 12:42:46 EDT 2020
Great— Thank you!
> On 16 Jun 2020, at 16:39, Matthew Brett <matthew.brett at gmail.com> wrote:
> 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)
> Neuroimaging mailing list
> Neuroimaging at python.org
More information about the Neuroimaging