[Neuroimaging] using nibabel to convert a dtscalar parcellation (1-N for each greyordinate) to a 4d (binary slice for each parcel) dtseries
Michiel Cottaar
michiel.cottaar at ndcn.ox.ac.uk
Sun Oct 25 07:50:37 EDT 2020
Hi Uri,
You will have to tell Cifti what is along this new axis you created. One way to do this is to use the cifti2 axes (https://nipy.org/nibabel/reference/nibabel.cifti2.html#module-nibabel.cifti2.cifti2_axes). After creating newdata this would look like:
>>> from nibabel import cifti2
>>> new_axis = cifti2.ScalarAxis([f"parcel {idx + 1}" for idx in range(N)]) # these are the names for all the parcels; you might want to replace them with something more meaningfull
>>> grayordinate_axis = dsobj.header.get_axis(1) # get a description of the greyordinate space from the loaded CIFTI file
>>> newobj = nb.Cifti2Image(newdata, (new_axis, grayordinate_axis)) # creates a new Cifti2 header based on these axes
This newobj will have the shape of (N, 64984) for N parcels.
However, based on your description I'm not completely sure if this is what you want to be doing. The output will still be a 2D CIFTI file rather than a 4D NIFTI file. If you want the latter, just reshape the newdata to be 4D using something like `newdata.T.reshape(64984, 1, 1, N)` and create a new nb.Nifti1Image object from that data.
Good luck,
Michiel
On 24 Oct 2020, at 19:05, Uri Elias <uri.urie at gmail.com<mailto:uri.urie at gmail.com>> wrote:
Hi All,
Top level - I'd like to apply dual regression on rest fMRI based on parcellation where my rs-fMRI data in in CIFTI format.
For a dual-regression SW I've chosen FSL, also because it works on Cifti (according to manual).
For parcellation I've chosen the Schaefer parcellation, as it is Cifti-available and also partially based on rest-fMRI.
Now, the Cifti parcellation file is a dscalar file (that is - a single volume/surface), with each greyordinate belongs to one of N parcels. FSL (AFAIU) requires a 4D file as a reference
Working with nibabel, reformatting the matrix is easy - reading it with nibabel and do something like: for k in range(N):
newdata[k,:] = (orgdata==k+1).astype(float)
Updating the Nifti header is also easy -
newobj = nb.Cifti2Image(newdata, dscobj.header, dscobj.nifti_header)
newobj.update_headers()
The problem with this way is the the Cifti header is not being updated -
newobj.header.matrix.get_data_shape()
yeilds
(1, 64984)
What's a good way of doing this? - either by sticking to the nibabel->FSL line right or by any alternative
Thanks all so much,
Uri
--
Uri Elias
Computational Neuropsychiatry Lab
Hadassah Hebrew University Medical School
[www.neuropsychiatrylab.com]<http://www.neuropsychiatrylab.com/>
[facebook]<https://www.facebook.com/uri.urie>
[linkedin]<https://www.linkedin.com/in/uri-elias-99a43546/>
_______________________________________________
Neuroimaging mailing list
Neuroimaging at python.org<mailto:Neuroimaging at python.org>
https://mail.python.org/mailman/listinfo/neuroimaging
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20201025/c7f0ccf7/attachment.html>
More information about the Neuroimaging
mailing list