incf-nidash / nidmresults-fsl

A python library to export FSL's feat results to NIDM-Results
http://nidm.nidash.org/specs/nidm-results.html
MIT License
3 stars 11 forks source link

Remove cluster call to get subject clusters in mm spaces #114

Closed cmaumet closed 5 years ago

cmaumet commented 7 years ago

Discussion with @pauldmccarthy to remove call to cluster to get subject-level clusters in mm space.

pauldmccarthy commented 7 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)
TomMaullin commented 5 years ago

This has now been addressed by PRs #134 and #135