Convert from CIFTI2 (HCP) to 3D array

Hey,

I’ve been working with fMRI images by treating them 3D volumes/arrays (for the MNI template it is a (91, 109, 91) sized array). So far, I’ve used nibabel to load NIFTI1 images as a 3D volume and it works seamlessly.

I’m now trying to extend the work I’m doing to HCP resting state fMRI data. However, the resting state data is in CIFTI2 format, and I’ve been trying to convert it into a 3D volume, but to no avail.

I’ll list a couple of things I’ve tried, and hopefully someone can point me to the right tools or tell me what I’ve been doing wrong.

  1. Connectome workbench: wb_command -cifti-convert -to-nifti [cifti file] [output file]
    This produces a file that nibabel loads as as (32767, 3, 1, 1200) - the 4th dimension is for time I think. I’m not sure how to convert this into a 3D volume (or 4D including a dimension for time)

  2. Loading CIFTI2 file using nibabel: I have tried iterating over the brain_models which have regions with voxel_indices_ijk. However, this creates images without surface information.

I’m not sure what I should be doing instead - how do I go about loading in CIFTI2 files as 3D matrices?

Thanks!

Not exactly a solution, but we’ve had the least trouble converting ciftis to gifti format, rather than rearranging into volumes (-cifti-convert will write a pair of giftis for the hemispheres (and subcortical as nifti)). We’d also tried working with cifti surfaces as “fake” volumes, but found the indexing issues (which voxel corresponds to which vertex) were a lot more problematic than working with surfaces in gifti format.

2 Likes

I am not 100% sure of this, but I have a hunch that the neuropythy library written by Noah Benson might have a solution to your problem. Try python -m neuropythy surface_to_image --help, for example.

2 Likes

Thanks for the responses!
I’ll try to post a more detailed solution here once I have a working solution :slight_smile:

EDIT

HCP actually has Nifti1 images for resting state on Amazon S3. Its strange because the only download I can find provides CIFTI files.

Hello @HarounH, I am dealing a similar problem. How did you solve the issue ?
thank you
Kaan