Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home Forum Using data sets vim-1: how to know space location of the voxels

vim-1: how to know space location of the voxels

Up to Using data sets

vim-1: how to know space location of the voxels

Posted by Jiancheng Sun at September 21. 2014

Hi, 

I would like to use the EstimatedResponses.mat for analysis. Variable dataTrn is 1,750 x ~25,000 matrix, where 25,000 is the number of voxels. I would like to know the space location of these voxels. How to do it? For example, I use following code to read a nii file in Python:

import nibabel as nib
img = nib.load('data/Sub1_Ses1_Run1_Trn.nii.gz')
img_np=img.get_data()
print img_np.shape

 

(64, 64, 18, 672)

 

In above array img_np(64,64,18), what are the index of 25,000 voxels in dataTrn? I need these space information in my current work.

 

Thanks

Jiancheng



Re: vim-1: how to know space location of the voxels

Posted by Mark Lescroart at October 28. 2014

Pardon the late reply. We had hoped that this would be obvious, but the indices for the EstimatedResponse voxels in the 64 x 64 x 18 scanned brain volume are stored in the voxIdx<S1|S2> variables. You can put the dataTrn<Subject> or dataVal<Subject> can be put back into 3D functional volume space by:

import h5py

import numpy as np

# Get data and index

hf = h5py.File('EstimatedResponses.mat')

trn = hf['dataTrnS1'].value

idx = int32(hf['voxIdxS1'].value).flatten()

# Pre-allocate brain

br = np.zeros(18*64*64)

# Estimated response for one image to 3D brain (and get rid of NaNs)

br[idx] = np.nan_to_num(trn[0])

# Reshape to brain volume

br3D = br.reshape((18,64,64)).T

Powered by Ploneboard
Document Actions