Closed cmaumet closed 5 years ago
Convert between subject voxels and subject world using nibabel and numpy.
import nibabel as nib
import numpy as np
import numpy.linalg as npla
img = nib.load('filtered_func_data.nii.gz')
# Transformation matrix from voxels to mm
voxToWorld = img.affine
# Transformation matrix from mm back to voxels
worldToVox = npla.inv(voxToWorld)
# Generate some random voxel coordinates.
# The 3D coordinates have to actually be
# 4D, with a 1 in the fourth dimension
voxels = np.ones((10, 4))
voxels[:, :3] = np.random.randint(1, 10, (10, 3))
# Convert to mm
mmcoords = np.dot(voxels, voxToWorld)
# Convert back to voxels
voxels = np.dot(mmcoords, worldToVox)
This has now been addressed by PRs #134 and #135
Discussion with @pauldmccarthy to remove call to
cluster
to get subject-level clusters in mm space.